I'm using Spring Boot (latest version, 1.3.6) and I want to create a REST endpoint which accepts a bunch of arguments and a JSON object. Something like:
curl -X POST http://localhost:8080/endpoint \
-d arg1=hello \
-d arg2=world \
-d json='{"name":"john", "lastNane":"doe"}'
In the Spring controller I'm currently doing:
public SomeResponseObject endpoint(
@RequestParam(value="arg1", required=true) String arg1,
@RequestParam(value="arg2", required=true) String arg2,
@RequestParam(value="json", required=true) Person person) {
...
}
The json
argument doesn't get serialized into a Person object.
I get a
400 error: the parameter json is not present.
Obviously, I can make the json
argument as String and parse the payload inside the controller method, but that kind of defies the point of using Spring MVC.
It all works if I use @RequestBody
, but then I loose the possibility to POST separate arguments outside the JSON body.
Is there a way in Spring MVC to "mix" normal POST arguments and JSON objects?