title: Spring MVC: @ResponseBody, 415 Unsupported Media Type
body: <p>I'm having trouble mapping a JSON Post to a particular Java Object to save it via <strong>Hibernate</strong></p>
  
  <p>Headers of the Ajax call are correctly set...</p>
  
  <pre><code>Accept          application/json
  Content-Type    application/json; charset=UTF-8
  </code></pre>
  
  <p>and the HTTP-Method is <strong>POST</strong></p>
  
  <p>Here comes my configuration...</p>
  
  <p>My Spring MVC function mapping looks like this</p>
  
  <pre><code>@RequestMapping(value = {"/save.json"},method = RequestMethod.POST)
  public ModelMap save(@RequestBody Seizure seizureObj,Model model) {
     ...
  }
  </code></pre>
  
  <p>in my container xml I have a <strong>ContentNegotiatingViewResolver</strong> like this</p>
  
  <pre><code>&lt;bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"&gt;
      &lt;property name="mediaTypes"&gt;
          &lt;map&gt;
              &lt;entry key="html" value="text/html" /&gt;
              &lt;entry key="json" value="application/json" /&gt;
          &lt;/map&gt;
      &lt;/property&gt;
      &lt;property name="viewResolvers"&gt;
          &lt;list&gt;
              &lt;bean id="viewResolver"
                  class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
                  &lt;property name="prefix" value="/WEB-INF/assets/" /&gt;
                  &lt;property name="suffix" value=".jsp" /&gt;
              &lt;/bean&gt;
          &lt;/list&gt;
      &lt;/property&gt;
      &lt;property name="defaultViews"&gt;
          &lt;list&gt;
              &lt;bean
                  class="org.springframework.web.servlet.view.json.MappingJacksonJsonView"&gt;
                  &lt;property name="prefixJson" value="false" /&gt;
                  &lt;property name="objectMapper" ref="jacksonObjectMapper" /&gt;
              &lt;/bean&gt;
          &lt;/list&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>in my container xml the part for jackson</p>
  
  <pre><code>&lt;bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapterConfigurer"
      init-method="init"&gt;
  
      &lt;property name="messageConverters"&gt;
          &lt;list&gt;
              &lt;bean id="marshallingHttpMessageConverter"
                  class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"
            &gt;
            &lt;property name="objectMapper" ref="jacksonObjectMapper" /&gt;
            &lt;/bean&gt;
          &lt;/list&gt;
      &lt;/property&gt;
  &lt;/bean&gt; 
  
  &lt;bean id="jacksonObjectMapper" class="org.codehaus.jackson.map.ObjectMapper" /&gt; 
  </code></pre>
  
  <p>I have </p>
  
  <ul>
  <li>jackson-core-asl-1.8.5</li>
  <li>jackson-mapper-asl-1.8.5</li>
  </ul>
  
  <p>in my /lib folder</p>
  
  <p>and Jackson works for a simple case like this</p>
  
  <pre><code>public class Simple {
    private int id;
  
    public int getId() {
      return id;
    }
  
    public void setId(int id) {
      this.id = id;
    }   
  }
  
  @RequestMapping(value = {"/saveSimple.json"},method = RequestMethod.POST)
  public ModelMap save(@RequestBody Simple simple,Model model) {
     ...
  }
  </code></pre>
  
  <p>when I test it with curl</p>
  
  <pre><code> curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"id":1}'  http://&lt;URL&gt;/saveSimple.json
  </code></pre>
  
  <p>No problems, but if I test it with the Hibernate object I get the message</p>
  
  <pre><code>415 Unsupported Media Type
  </code></pre>
  
  <p>any ideas.</p>