title: Receiving a Bad Request Error (400) after $.ajax POST on Spring Controller
body: <p>Hello StackOverFlow(s)</p>
  
  <p>I'm running with this issue since more than 2 hours now 
  It's simple</p>
  
  <p><strong>I'm trying to send a JSON object to a Spring Controller by using a $.ajax POST call</strong></p>
  
  <p>I'm using AngularJS but that point is okey</p>
  
  <p>here's the code of both server and client and the spring configuration</p>
  
  <p><strong>Thank's in advance</strong></p>
  
  <p>JQuery :</p>
  
  <pre><code>    $scope.push = function() {
      $.ajax({
          type: "PUT",
          url:"rest/todo/greeting/",
          data : {id:"1",title:"ajax",description:"ajax"},
          dataType: "json",
          contentType : "application/json",
          success : function(data) {
              $log.info(data)
          }
      })
  }
  </code></pre>
  
  <p>Spring Controller :</p>
  
  <pre><code>@Controller
  @RequestMapping("/todo")
  public class TodoController {
  @RequestMapping(value = "/greeting", method = RequestMethod.PUT,consumes="application/json",produces="text/html")
  public @ResponseBody String push(@RequestBody Todo todo) {
      System.out.println(todo.getTitle());
      return "test";
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Spring Configuration :</p>
  
  <pre><code>&lt;mvc:annotation-driven /&gt;
  &lt;context:component-scan base-package="org.lab.todo.controller" /&gt;
  &lt;bean id="defaultViews" class="org.springframework.web.servlet.view.json.MappingJackson2JsonView" /&gt;
  </code></pre>
  
  <p></p>
  
  <p>web.xml :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"&gt;
  
  &lt;listener&gt;
      &lt;listener-class&gt;
          org.springframework.web.context.ContextLoaderListener
      &lt;/listener-class&gt;
  &lt;/listener&gt;
  
  &lt;!--
      Spring WEBMVC/REST Controllers
  --&gt;
  &lt;servlet&gt;
      &lt;servlet-name&gt;todo-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;todo-dispatcher&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/rest/*&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p></p>
  
  <p>Ajax Call Update :</p>
  
  <pre><code>    $scope.push = function() {
      var jsonString = {id:"1",title:"ajax",description:"ajax"};
      var Todo = function(){}
      Todo.id = "id";
      Todo.title = "ajax";
      Todo.description = "ajax";
      $.post("rest/todo/greeting",JSON.stringify(Todo),function(response){console.log(response)},'json');
  }
  </code></pre>
  
  <p>Fiddle Raw Request Header :</p>
  
  <pre><code>POST http://localhost:8080/todo-rest/rest/todo/greeting HTTP/1.1
  Host: localhost:8080
  Connection: keep-alive
  Content-Length: 0
  Accept: application/json, text/javascript, */*; q=0.01
  Origin: http://localhost:8080
  X-Requested-With: XMLHttpRequest
  User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko)     Chrome/24.0.1312.56 Safari/537.17
  Referer: http://localhost:8080/todo-rest/
  Accept-Encoding: gzip,deflate,sdch
  Accept-Language: en-US,en;q=0.8,fr;q=0.6
  Accept-Charset: UTF-8,*;q=0.5
  </code></pre>
  
  <p>Fiddle Response Header</p>
  
  <pre><code>HTTP/1.1 415 Unsupported Media Type
  Server: Apache-Coyote/1.1
  Content-Type: text/html;charset=utf-8
  Content-Length: 1048
  Date: Thu, 31 Jan 2013 17:11:40 GMT
  </code></pre>