grails @BindUsing command Object

908 Views Asked by At

I am using grails 2.5.5 and the problem is when I'm using a command Object, I want to change the format of the data I get with the @BindUsing annotation.

@Validatable
class FooCommand extends BarCommand{
    @BindUsing({obj, source -> return source['foo'].collect{it['id']}})
    List<Long> foo

static constraints = {foo(nullable:true)}
}

the BindUsing closure never gets executed. What is the problem and how to solve?

JSONData = {"foo":[
                   {'id':5}, 
                   {'id':4}
                  ]
           }
FooCommand fooCommand = FooCommand(JSONData)
fooCommand.validate()

EDIT: To be clear: the problem is that the data change from format,from list of maps, to just a list of longs. Is there a way to do this with the BindUsing or will i just have to do it in the controller each time?

0

There are 0 best solutions below