I have a standard Spring 4 MVC application. I have REST endpoints that take the ResponseBody json and maps to my Java objects. This is working great.
But now I have a need to get the raw JSON, as I do not have a Java object to map it to. My endpoint looks like this:
@RequestMapping(value="", method = RequestMethod.POST)
@ResponseBody
public Object createObject(@RequestBody JsonObject objectJson) {
When I POST json to this endpoint I get an empty JSON string. The objectJson is not NULL, but when I debug like this:
System.out.println(objectJson.toString());
I get: {}
when I change the method signature to:
public Object createObject(@RequestBody String objectJson) {
I get a 400 "The request sent by the client was syntactically incorrect"
How do I get the JSON being sent in, either as a String that I can parse manually, or the JsonObject and I can use?