In a Grails 2.5.X app, I can directly bind request data to a command object field of type Map
like so:
class MyController {
def myAction(Command command) {
Map requestData = command.data
}
}
class Command {
Map data
}
It seems that internally Grails uses Gson for the parsing of the JSON data. If for example, the request data is {"page": 6}
the corresponding Map
will be
[page: new LazilyParsedNumber(6)]
i.e. the value stored in the Map
is an instance of com.google.gson.internal.LazilyParsedNumber
.
This is problematic for me. I would prefer if the Map
were equivalent to that which would be created by:
new groovy.json.JsonSlurper().parseText('{"page": 6}')
which is:
[page: new Integer(6)]
I've looked into the various options for customising the databinding, and none of them hook into the pipeline sufficiently early. In other words, no matter which of the options I choose, the request data has already been processed by Gson.
Is it possible to replace Gson with JsonSlurper
as the default parser of JSON request data?