title: mapping json to a pojo using MappingJacksonHttpMessageConverter and POST
body: <p>I am trying to make something very similar to this post using Spring MVC 3.1:</p>
  
  <p><a href="https://stackoverflow.com/questions/5908466/jquery-spring-mvc-requestbody-and-json-making-it-work-together">JQuery, Spring MVC @RequestBody and JSON - making it work together</a></p>
  
  <p>and trying to get the response as a custom class such as "FooBar" in the example.</p>
  
  <p>my ajax call looks like this:</p>
  
  <pre><code>// var rule = "giveThisATry";
  var rule = {
      id : 1,
      name : {
          name1 : "1",
          name2 : "2",
          name3 : "3",
          name4 : "4"
      }
  };
  $.ajax({
      url : "http://localhost:8080/spring2/save",
      type : "POST",
      dataType : "json",
      //contentType : "application/json; charset=utf-8",
      data : rule,
      success : function(data) {
          alert("success saveRule: " + data);
      },
      error : function(request, status, error) {
          alert("error saveRule: " + request.responseText);
      }
  });
  </code></pre>
  
  <p>and my rest method looks like this:</p>
  
  <pre><code>@RequestMapping(method = RequestMethod.POST, value = "/save")
  public @ResponseBody MyClass save(@RequestBody MyClass instance, final HttpServletResponse response) {
      response.setHeader("Access-Control-Allow-Origin", "*");
      return MyDB.Save(instance);
  }
  </code></pre>
  
  <p>Now no matter what I do, Spring would not map the ajax call to this method.
  Also if i uncomment the line in my ajax call :</p>
  
  <pre><code>contentType : "application/json; charset=utf-8",
  </code></pre>
  
  <p>Chrome would change the "request-method" to "OPTIONS" :</p>
  
  <pre><code>Request Method:OPTIONS
  Status Code:200 OK
  Request Headersview source
  Accept:*/*
  Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
  Accept-Encoding:gzip,deflate,sdch
  Accept-Language:en-US,en;q=0.8
  Access-Control-Request-Headers:Origin, Content-Type, Accept
  Access-Control-Request-Method:POST
  Cache-Control:no-cache
  Connection:keep-alive
  Host:localhost:8080
  Origin:http://127.0.0.1:8020
  Pragma:no-cache
  Referer:http://127.0.0.1:8020/JQueryPOC/src/index.html
  User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko)     Chrome/17.0.963.56 Safari/535.11
  Response Headersview source
  Allow:GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS
  Content-Length:0
  Date:Fri, 15 Jun 2012 15:07:19 GMT
  Server:Apache-Coyote/1.1
  </code></pre>
  
  <p>Now how can i test/debug/have control over the MappingJacksonHttpMessageConverter so that i can map the json to a pojo using requestbody or something else ?</p>