Skip to content

Instantly share code, notes, and snippets.

@gunnarmorling
Last active December 20, 2015 03:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gunnarmorling/6063349 to your computer and use it in GitHub Desktop.
Save gunnarmorling/6063349 to your computer and use it in GitHub Desktop.
Options for configuring group conversions via the API (https://hibernate.atlassian.net/browse/HV-642)
ConstraintMapping mapping = config.createConstraintMapping();
mapping.type( GreetingService.class )
.method( "greet", User.class )
.returnValue()
.valid()
.convertGroup( Default.class ).to( User.class )
.convertGroup( Foo.class ).to( Bar.class );
//more "fluent" name?
ConstraintMapping mapping = config.createConstraintMapping();
mapping.type( GreetingService.class )
.method( "greet", User.class )
.returnValue()
.valid()
.convertingFrom( Default.class ).to( User.class )
.convertingFrom( Foo.class ).to( Bar.class );
//using an object for representing conversions
ConstraintMapping mapping = config.createConstraintMapping();
mapping.type( GreetingService.class )
.method( "greet", User.class )
.returnValue()
.valid()
.convertGroup( new GroupConversion( Default.class, User.class ) )
.convertGroup( new GroupConversion( Foo.class, Bar.class ) );
//using an object within valid(GroupConversion... conversions)
ConstraintMapping mapping = config.createConstraintMapping();
mapping.type( GreetingService.class )
.method( "greet", User.class )
.returnValue()
.valid(
new GroupConversion( Default.class, User.class ),
new GroupConversion( Foo.class, Bar.class )
);
ConstraintMapping mapping = config.createConstraintMapping();
mapping.type( GreetingService.class )
.method( "greet", User.class )
.returnValue()
.valid()
.withConversion( Default.class, User.class )
.withConversion( Foo.class, Bar.class );
@hferentschik
Copy link

On first impulse 3 or 1a

@emmanuelbernard
Copy link

For some reason, I am hesitant to link group conversion to the valid call. Granted that's the case in the spec but we decided to leave them separate annotation wise.

1a has my preference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment