Reputation: 374
I'm writing REST API for my app.
Using JSON payload in the POST request:
{
availableAfter: "2014-03-16"
canRead: true
rightName: "dsa"
}
The problem is that, in the controller's params there are no values from payload.
But, despite that, I can read them using properties[*]
syntax, like this:
right.properties['rightName', 'canRead'] = params;
right.availableAfter = params.date('availableAfter', 'yyyy-MM-dd');
Properties 'rightName' and 'canRead' are set OK. 'availableAfter' is not(null even if taken with params.availableAfter
).
Why is it differs?
UPDATE: Grails v 2.3.6
Upvotes: 4
Views: 2171
Reputation: 20707
You have to use request.JSON
to get a hold of your JSON-body.
The params
object doesn't contain it, unless you serialize your JSON object in the client and pass it as a parameter.
Upvotes: 5