How to consume json object from Spring MVC controller input directly


This is small note about the json input directly to Spring MVC controller side, jackson will auto convert it to Java object you want:

  1. Make sure has this jar added


2.  Controller side

@RequestMapping(value = urlPatternController, method = RequestMethod.POST)
public @ResponseBody Person createPerson(@RequestBody Person jsonString) {
   Person person=personService.savedata(jsonString);
   return person;

@RequestBody – Covert Json object to java
@ResponseBody– convert Java object to json

3. JS client side :


$.ajax("<%=path%>/web/urlPatternController", {
                           dataType: 'json',
                           data: person


Link can be refered