Reputation: 830
I'd like to POST JSON and have Jackson convert it to a POJO, but for now I can't even POST a simple String parameter.
I'm using Jackson 2.3.2 (jackson-core and jackson-databaind)
I'm using Spring 3.2.8.RELEASE (spring-context, spring-webmvc)
My Controller looks like this:
@RequestMapping(value="add-name", method=RequestMethod.POST, headers = "Accept=application/json")
public String addName(@RequestParam(value = "name", required = false) String name) {
LOG.info(String.format("name: %s", name));
return "name";
}
I POST to this Controller with data like this:
{ "name" : "my_name" }
The response I receive is 400 Bad Request
Note: I'm submitting the POST via jQuery.post(), but to remove that as a variable, I'm also submitting POST via FF Poster add-on specifying the URL, Content Type (application/json), and data as above.
Edit: I think the issue may be that the Jackson library isn't even being called. I took it out of the dependencies and nothing changes, no different error/exception, I still simply get a 400 Bad Request
response.
Edit 2: Even if I take out the parameter to addName
completely and post an empty body {}
I still get a 400 Bad Request
Upvotes: 2
Views: 10193
Reputation: 830
I downgraded to Spring 3.1.1.RELEASE and Jackson 1.9.9 and it works now. Seems like a hack. I thought Spring 3.2 and Jackson 2 were compatible.
Upvotes: 2
Reputation: 1702
You are posting raw data in the body, but your controller is looking for a parameter named name
. Either post with a parameter name
whose value is my_name
, or use @RequestBody
in the handler to pass in the JSON object.
Upvotes: 3