Using Jackson I can able to convert the object to JSON
@RequestMapping(value="getMessage.test", headers = "Accept=application/json" ,method = RequestMethod.POST)
public @ResponseBody TestObject getMessage(){
TestObject object=new TestObject();
object.setMessage("Hello JQuery");
return object;
}
The above code works well… But conversion from JSON to Object gives WARN PageNotFound – No matching handler method found for servlet request: path ‘/setMessage.test’, method ‘POST’, parameters map[[empty]] Below is the code. Where i am going wrong..
@RequestMapping(value="setMessage.test", method = RequestMethod.POST, headers = "Accept=application/json" )
public void setMessage(@RequestBody TestObject test,HttpServletRequest request){
System.out.println("Inside setting message");
System.out.println(test.getMessage());
}
JQuery Ajax calls…
$.ajaxSetup({ contentType: "application/json; charset=UTF-8" });
$.post('getMessage.test',function(response) {
alert(response.message);
}, 'json');
$.post( 'setMessage.test', {message: 'Hello Spring'});
Finally i got the fix. There is a bug in JQuery $.post method which is not setting the proper contenttype. So setting the contenttyple in the ajaxsetup works well… and i used jquery.json-2.3.min.js to create a json object…..