Client code:
$.ajax({
type: "POST",
url: "../web/zittles",
data: jsonformatdata,
contentType: "application/json",
dataType: "json",
success: function(data)
{
alert("data from server : "+data);
},
error: function(jqXHR, textStatus, errorThrown)
{
alert("jqXHR.status = "+jqXHR.status); //getting status code 400 here
}
});
Output json data:
{
"id": 1,
"No": "1234",
"Desc": "Testing"
}
Java class:
public class Fizzle implements Serializable
{
private String id;
private String No;
private String Desc;
// getters and setters
}
Spring 3 Controller:
@RequestMapping(value = '/zittles', method = RequestMethod.POST, headers ="Content-Type=application/json")
public @ResponseBody void doSomeThing (@RequestBody Fizzle fizzle) {
//do something here
}
app-servlet.xml has
<mvc:annotation-driven/>
/lib folder of tomcat has
jackson-core-lgpl-1.9.10.jar
jackson-mapper-lgpl-1.9.10.jar
Getting error with status code 400 -
"The request sent by the client was syntactically incorrect"
When I change the Controller code as shown below, it takes the json data as string.
public @ResponseBody void doSomeThing (@RequestBody String fizzle) {}
Ideally Jackson should automatically map the json data to Fizzle object.
What is it that I am missing here. Is there anything else that has to be done to configure the Jackson parser correctly?
Help please.