Details
Description
This may well be present in earlier versions also.
When switching from a normal URL mapping to a named URL mapping, the request JSON is no longer automatically parsed.
UrlMappings.groovy
class UrlMappings {
static mappings = {
"/user/$id"(controller: "user", parseRequest: true) {
action = [POST:"update"]
}
name userId: "/nameduser/$id" {
controller = "user"
parseRequest = true
action = [POST:"update"]
}
}
}
UserController.groovy
package restful class UserController { def update() { println params assert params.username == "NewUsername" render "ok" } }
POSTing to /user/1 with the JSON
{'username': "NewUsername"}is successful, however posting the same data to /nameduser/1 fails as the username is not added to params.
Successful request:
curl -i -H 'Content-Type:application/json' -X POST -d '
' http://127.0.0.1:9090/restful/user/1
Failing request:
curl -i -H 'Content-Type:application/json' -X POST -d '
' http://127.0.0.1:9090/restful/nameduser/1
[id:1, action:[POST:update], controller:user] | Error 2011-12-05 12:05:05,665 ["http-bio-9090"-exec-10] ERROR errors.GrailsExceptionResolver - PowerAssertionError occurred when processing request: [POST] /restful/nameduser/1 assert params.username == "NewUsername" | | | | null false [id:1, action:[POST:update], controller:user]. Stacktrace follows:
FYI...
I do not think this is peculiar to named url mappings. I think the problem applies to all mappings defined with a closure and no named arguments.
This works:
"/path"(controller: 'foo') { parseRequest = true }This does not work:
"/path" { controller = 'foo' parseRequest = true }We will get it resolved right away.