title: Posting JSON to Controller returns 400 Bad Request
body: <p>I am developing RESTful services.
  I am not able to POST JSON data to controller.</p>
  
  <p>I am using the following dependencies:</p>
  
  <ul>
  <li>Spring : 3.2.3.RELEASE</li>
  <li>Jackson : 1.9.6</li>
  </ul>
  
  <p>I also tried:</p>
  
  <ul>
  <li>Spring 3.2.3.RELEASE w/ Jackson 1.9.9</li>
  <li>Spring 3.1.1.RELEASE w/ Jackson 1.9.9</li>
  </ul>
  
  <p>as suggested here <a href="https://stackoverflow.com/questions/22869403/posting-json-to-spring-mvc-controller-returns-400-bad-request">POSTing JSON to Spring MVC Controller Returns 400 Bad Request</a></p>
  
  <p>I made entries of MessageConverters also,</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;mvc:annotation-driven&gt;
      &lt;mvc:message-converters&gt;
          &lt;bean class="org.springframework.http.converter.StringHttpMessageConverter"/&gt;
          &lt;bean class="org.springframework.http.converter.ResourceHttpMessageConverter"/&gt;
          &lt;bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/&gt;
      &lt;/mvc:message-converters&gt;
  &lt;/mvc:annotation-driven&gt;
  </code></pre>
  
  <h3>Controller</h3>
  
  <pre><code>@Controller
  @RequestMapping(value="/todo", consumes="application/json", produces="application/json")
  //@RequestMapping(value="/todo", consumes="text/plain", produces="application/json")
  public class TodoRestService {
     Logger logger = LoggerFactory.getLogger(TodoService.class);
     @Autowired
     private TodoService todoService;
  
     @RequestMapping(value="/{id}", method= RequestMethod.GET)
     @ResponseBody public Todo find(@PathVariable("id") Long id) {
       Todo todo = todoService.find(id);
       return todo;
     }
  
     @RequestMapping(method=RequestMethod.POST)
     @ResponseBody public Todo create(@RequestBody Todo todo) {
     //public Todo create(@RequestBody String todo) {
     //public Todo create(@RequestParam("todo") String todo) {
       System.out.println(todo);
       todoService.create(newTodo);
       return newTodo;
    }
  }
  </code></pre>
  
  <h3>POJO</h3>
  
  <pre><code>public class TODO {
    private String firstName;
    private String lastName;
  
    //getter setters
  } 
  </code></pre>
  
  <p>I am using postman to POST the JSON</p>
  
  <p>I have set Content-Type as application/json</p>
  
  <p>form data -----
  name = todo
  value = {"firstName":"nilam","lastName":"naik"}</p>
  
  <p>method = POST</p>
  
  <p>I am getting 400 Bad Request.</p>
  
  <p>But If I changed data type of parameter annotated with @RequestBody from TODO to String then<br>
  I am getting something like,</p>
  
  <pre class="lang-none prettyprint-override"><code>------WebKitFormBoundaryu6banLlTPiPudsBB
  Content-Disposition: form-data; name="todo"
  
  {"firstName":"nilam","lastName":"naik"}
  ------WebKitFormBoundaryu6banLlTPiPudsBB--
  </code></pre>
  
  <p>I also have Jackson on my classpath.</p>
  
  <p>If I changed attribute consumes from application/json to text/plain and </p>
  
  <p>@RequestBody String todo then I get,</p>
  
  <pre><code>{"firstName":"nilam","lastName":"naik"}
  </code></pre>
  
  <p>But I don't want to manually convert the String to Java Object.  But I don't understand why @RequestBody is not able to convert my JSON data to Java Object.</p>
  
  <h3>pom.xml</h3>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0"      
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-      v4_0_0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;groupId&gt;com.orci&lt;/groupId&gt;
      &lt;artifactId&gt;OrciMavenTutorial&lt;/artifactId&gt;
      &lt;packaging&gt;war&lt;/packaging&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;name&gt;OrciMavenTutorial Maven Webapp&lt;/name&gt;
      &lt;url&gt;http://maven.apache.org&lt;/url&gt;
  
      &lt;properties&gt;
          &lt;!-- &lt;org.springframework.version&gt;3.2.3.RELEASE&lt;/org.springframework.version&gt; --&gt;
          &lt;org.springframework.version&gt;3.1.1.RELEASE&lt;/org.springframework.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;junit&lt;/groupId&gt;
              &lt;artifactId&gt;junit&lt;/artifactId&gt;
              &lt;version&gt;3.8.1&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-orm&lt;/artifactId&gt;
              &lt;version&gt;${org.springframework.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-jdbc&lt;/artifactId&gt; 
              &lt;version&gt;${org.springframework.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-web&lt;/artifactId&gt; 
              &lt;version&gt;${org.springframework.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
              &lt;version&gt;${org.springframework.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
               &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
               &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
               &lt;version&gt;4.2.2.Final&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
               &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
               &lt;artifactId&gt;javax.servlet-api&lt;/artifactId&gt;
               &lt;version&gt;3.0.1&lt;/version&gt;
               &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
               &lt;groupId&gt;org.apache.derby&lt;/groupId&gt;
               &lt;artifactId&gt;derbyclient&lt;/artifactId&gt;
               &lt;version&gt;10.5.3.0_1&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
                &lt;groupId&gt;org.apache.derby&lt;/groupId&gt;
                &lt;artifactId&gt;derby&lt;/artifactId&gt;
                &lt;version&gt;10.5.3.0_1&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
                &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
                &lt;artifactId&gt;slf4j-api&lt;/artifactId&gt;
                &lt;version&gt;1.7.7&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
                &lt;groupId&gt;org.codehaus.jackson&lt;/groupId&gt;
                &lt;artifactId&gt;jackson-core-asl&lt;/artifactId&gt;
                &lt;!-- &lt;version&gt;1.9.6&lt;/version&gt; --&gt;
                &lt;!-- &lt;version&gt;1.4.2&lt;/version&gt; --&gt;
                &lt;!-- &lt;version&gt;1.9.9&lt;/version&gt; --&gt;
                &lt;version&gt;1.9.7&lt;/version&gt;
          &lt;/dependency&gt;
  
         &lt;dependency&gt;
               &lt;groupId&gt;org.codehaus.jackson&lt;/groupId&gt;
               &lt;artifactId&gt;jackson-mapper-asl&lt;/artifactId&gt;
               &lt;!-- &lt;version&gt;1.9.6&lt;/version&gt; --&gt;
               &lt;!-- &lt;version&gt;1.4.2&lt;/version&gt; --&gt;
               &lt;!-- &lt;version&gt;1.9.9&lt;/version&gt; --&gt;
               &lt;version&gt;1.9.7&lt;/version&gt;
         &lt;/dependency&gt;
   &lt;/dependencies&gt;
   &lt;build&gt;
       &lt;finalName&gt;OrciMavenTutorial&lt;/finalName&gt; 
   &lt;/build&gt;
  </code></pre>
  
  <p>Please someone help me.</p>