Groovy Documentation

org.grails.databinding
[Java] Annotation Type BindUsing

java.lang.Object
  org.grails.databinding.BindUsing

@java.lang.annotation.Retention(RetentionPolicy.RUNTIME)
public @interface BindUsing

This annotation may be applied to a class or to a field to customize the data binding process. When the annotation is applied to a field, the value assigned to the annotation should be a Closure which accepts 2 parameters. The first parameter is the object that data binding is being applied to. The second parameter is a Map containing the values being bound to the object. The value returned by the Closure will be bound to the field. The following code demonstrates using this technique to bind an upper case version of the value in the Map to the field.

class SomeClass {
    @BindUsing({
        obj, source -> source['name']?.toUpperCase()
    })
    String name
}
When the annotation is applied to a class, the value assigned to the annotation should be a class which implements the BindingHelper interface. An instance of that class will be used any time a value is bound to a property in the class that this annotation has been applied to.
@BindUsing(SomeClassWhichImplementsBindingHelper)
class SomeClass {
    String someProperty
    Integer someOtherProperty
}
Authors:
Jeff Brown
See Also:
BindingHelper
Since:
2.3


Required Element Summary
java.lang.Class value

   
Method Summary
 
Methods inherited from class java.lang.Object
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()
 

Element Detail

value

public java.lang.Class value


 

Groovy Documentation