title: Spring MVC @RequestBody gives 415 error
body: <p>No matter what I try the request to the dispatcher servlet gives back an HTTP 415 error.  The Content-Type is set to application/json in the request.</p>
  
  <p>It seems the message converter is not mapping the request to the object.</p>
  
  <p>I have all the Jackson dependencies in my POM:</p>
  
  <pre><code>    &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-databind-version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.fasterxml.jackson.module&lt;/groupId&gt;
          &lt;artifactId&gt;jackson-module-jaxb-annotations&lt;/artifactId&gt;
          &lt;version&gt;2.4.1&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;version&gt;1.9.13&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.sun.xml.bind&lt;/groupId&gt;
          &lt;artifactId&gt;jaxb-impl&lt;/artifactId&gt;
          &lt;version&gt;2.2.7&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.xbean&lt;/groupId&gt;
          &lt;artifactId&gt;xbean-spring&lt;/artifactId&gt;
          &lt;version&gt;3.7&lt;/version&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p>Controller class:</p>
  
  <pre><code>@RequestMapping(value = "/login", method = RequestMethod.POST, headers = {"Accept=application/json"}, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
  @ResponseBody
  public DriverLoginResponseDTO login(@RequestBody MyDTO dto)
  {
      System.out.println("login method hit!");
      LoginResponseDTO resp = null;
  
      try {
          resp = loginService.processLogin(dto);
      }
      catch (Exception cde) {
          resp = new LoginResponseDTO();
          resp.setMessage("ERROR");
      }
  
      // Return response object
      return resp;
  } // login
  </code></pre>
  
  <p>I've tried adding the accepts, consumes, produces in the @RequestMapping to no avail.</p>
  
  <p>I can get the correct JSON response with the HttpServletRequest as the method parameter:</p>
  
  <pre><code>@RequestMapping(value = "/login3", method = RequestMethod.POST)
  @ResponseBody
  public DriverLoginResponseDTO login3(HttpServletRequest request)
  {
      String line;
      StringBuilder sb = new StringBuilder();
  
      InputStream is;
      try {
          is = request.getInputStream();
          BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
          while ((line = reader.readLine()) != null) {
              sb.append(line).append("\n");
          }
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
      System.out.println("login3 method hit!");
      System.out.println("JSON string received: " + sb.toString());
  
      LoginResponseDTO resp = null;
  
      try {
          resp = loginService.processLogin(new MyDTO());
      }
      catch (Exception cde) {
          resp = new LoginResponseDTO();
          resp.setMessage("ERROR");
      }
  
      // Return response object
      return resp;
  } // login
  </code></pre>
  
  <p>This one shows the correct JSON string when written to System.out.  Something is not mapping the JSON request to the RequestBody object in the 1st "login" method above but I cannot see what is missing.</p>
  
  <p>I don't know if this is relevant but Websphere is also throwing the following error:</p>
  
  <p>SRVE8094W: WARNING: Cannot set header. Response already committed.</p>