Grails 3.1.1 - command object data binding does not play well with UrlMappings params
- Dominant language
- Groovy
- Stars
- 2.9k
- Forks
- 975
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 92
Description
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
Contributor guide
Research direction
Reproduce the issue with the shown UrlMappings entry, BookController.index, SomeCommandObject, and the HTTPie POST examples. Read the command-object data-binding path and the referenced GRAILS-11263 context; done means a JSON body binds someString while the UrlMappings id remains available as 1.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100