grails-core icon indicating copy to clipboard operation
grails-core copied to clipboard

Grails 3.1.1 - command object data binding does not play well with UrlMappings params

Open AleksanderGrzybowski opened this issue 9 years ago • 9 comments

I have an issue regarding data binding from JSON body to command object. I can provide sample app, but for now here are relevant snippets

"/api/someEndpoint/$id?"(controller: 'book', action: 'index', method: 'POST')
class BookController {
    def index(SomeCommandObject cmd) {
        render ([paramsAre: params, commandIs: cmd] as JSON)
    }
}

class SomeCommandObject {
    Long id
    String someString
    Integer someInteger
}

When POST-ing empty request to :8080/api/someEndpoint/1 the 'id' field of a command object is bound correctly, however including JSON, like this (using httpie)

http POST :8080/api/someEndpoint/1 someString=abc

causes 'someString' to bind but 'id' is null. I would expect these two sources of data (body and params coming from UrlMappings) to be merged. This issue seems relevant https://jira.grails.org/browse/GRAILS-11263

AleksanderGrzybowski avatar Feb 16 '16 13:02 AleksanderGrzybowski