title: Spring MVC request with null response in Json to Java object conversion
body: <p>My ajax request in spring mvc</p>
  
  <pre><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/json2/20150503/json2.js"&gt;&lt;/script&gt;
      &lt;script&gt;
      $(document).ready(function(){
          var producer = "producer";
          var model = "model";
          var price = "1";
          var ResponseModel = {};
          ResponseModel.producer=producer;
          ResponseModel.model=model;
          ResponseModel.price=price;
          $.ajax({
              url : '/ajaxtest',
              data: JSON.stringify({"editUserRequest":ResponseModel}),
              type: "POST",
              async: true,
              beforeSend: function(xhr) {
                  xhr.setRequestHeader("Accept", "application/json");
                  xhr.setRequestHeader("Content-Type", "application/json");
              },
  
              success : function(data) {
                  alert("success");
                  console.log(data);
              },
              error:function(data) {
                  alert("errorxxx");
                  console.log(data);
              }
          });
      });
  &lt;/script&gt; 
  </code></pre>
  
  <p>Model</p>
  
  <pre><code>@JsonSerialize
  public class ResponseModel implements Serializable {
      public ResponseModel(){}
      public String getProducer() {
          return producer;
      }
  
      public void setProducer(String producer) {
          this.producer = producer;
      }
  
      public String getModel() {
          return model;
      }
  
      public void setModel(String model) {
          this.model = model;
      }
  
      public String getPrice() {
          return price;
      }
  
      public void setPrice(String price) {
          this.price = price;
      }
  
      private String producer;
      private String model;
      private String price;
  }
  </code></pre>
  
  <p>and spring MVC controller</p>
  
  <pre><code>@Controller
  @RequestMapping("/")
  public class HelloController {
      @RequestMapping(method = RequestMethod.GET)
      public String printWelcome(ModelMap model) {
          model.addAttribute("message", "Hello world!");
          return "hello";
      }
      //@ModelAttribute(value="editUserRequest")
      @RequestMapping(value = "/ajaxtest", method = RequestMethod.POST,consumes=MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
      public @ResponseBody
      String getTime(@ModelAttribute(value="editUserRequest")  ResponseModel editUserRequest,HttpServletRequest request,HttpServletResponse response) {
  
  
          String result = editUserRequest.getModel()+editUserRequest.getPrice()+editUserRequest.getProducer();
          //String result = "editUserRequest";
          //System.out.println("Debug Message from CrunchifySpringAjaxJQuery Controller.." + new Date().toString());
          return result;
      }
  }
  </code></pre>
  
  <p>web.xml is</p>
  
  <pre><code>&lt;web-app version="2.4"
      xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
      http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"&gt;
  
      &lt;display-name&gt;Spring MVC Application&lt;/display-name&gt;
  
      &lt;servlet&gt;
          &lt;servlet-name&gt;mvc-dispatcher&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
  
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;mvc-dispatcher&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>and dispatcher servlets is</p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:context="http://www.springframework.org/schema/context"
         xmlns:mvc="http://www.springframework.org/schema/mvc"
         xsi:schemaLocation="http://www.springframework.org/schema/beans
          http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"&gt;
  
      &lt;context:component-scan base-package="com.springapp.mvc"/&gt;
      &lt;context:annotation-config /&gt;
      &lt;mvc:annotation-driven /&gt;
      &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
          &lt;property name="prefix" value="/WEB-INF/pages/"/&gt;
          &lt;property name="suffix" value=".jsp"/&gt;
      &lt;/bean&gt;
  
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>after sending ajax request in firebug it shows null result by post is done successfully by lands in ajax error .</p>
  
  <p><a href="https://i.stack.imgur.com/gN64G.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gN64G.png" alt="enter image description here"></a></p>
  
  <p>I have pom.xml with <code>&lt;jackson.version&gt;2.6.3&lt;/jackson.version&gt;</code></p>
  
  <pre><code>&lt;!-- Need this for json to/from object --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
              &lt;artifactId&gt;jackson-core&lt;/artifactId&gt;
              &lt;version&gt;${jackson.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
              &lt;artifactId&gt;jackson-databind&lt;/artifactId&gt;
              &lt;version&gt;${jackson.version}&lt;/version&gt;
          &lt;/dependency&gt;
  </code></pre>
  
  <p>But can not use it map in Spring MVC 4 json to java object. How to solve it??</p>