3

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?

miThom
  • 373
  • 2
  • 11
  • I've created the command you mentioned, empty `BarCommand`, and simple controller with one action `def index(FooCommand foo) {}` After running `http://localhost:8080/untitled/simpleController?foo={}` from my browser `BindUsing` closure is executing. Could you try to do the same manipulations? – Taras Kohut Jul 30 '16 at 23:33
  • I'll give it a try in the evening, how did you check if the bindUsing gets executed? I tried it with prints/logging. – miThom Aug 01 '16 at 15:32
  • I simply used breakout. – Taras Kohut Aug 01 '16 at 16:04
  • i do not have acces to breakpoints in debugmode because i can only run grails 2.5.5 in forked mode (havent set up forked debugger yet). I managed to confirm that in your case the bindUsing gets executed only if the databinding (not the constraints) would finish succesfully without the bindUsing. – miThom Aug 01 '16 at 21:13

0 Answers0