title: Spring REST service not consuming JSON
body: <p>I am having some difficulty using Spring's built-in JSON consumption using Jackson with REST web services. If I define the following:</p>
  
  <pre><code>...
  @RequestMapping(value="/stub")
  public void doSomething(@RequestBody User user) {
      System.err.println("In method");
      ...
  }
  </code></pre>
  
  <p>... it never reaches the method. I have Jackson in the classpath. However, when I manually use Jackson:</p>
  
  <pre><code>@RequestMapping(value="/stub")
  public void doSomething(@RequestBody String user) {
      System.err.println("In method");
  
      User newUser = null;
  
      try {
          user = URLDecoder.decode(user, "UTF-8");
      } catch (UnsupportedEncodingException e1) {...}
  
      try {
          newUser = new ObjectMapper().readValue(user, User.class);
      } catch (Exception e) {...}
  }
  </code></pre>
  
  <p>... it works perfectly. The <code>User</code> object gets created correctly with all the correct values, so I know the JSON is correct. Does it have something to do with the decoding? As far as I know from Spring 2.5 the decoding is on by default. Maybe I am missing something else, maybe a configuration step. My <code>web.xml</code> is as follows:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns="http://java.sun.com/xml/ns/javaee"
      xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
      xsi:schemaLocation="
          http://java.sun.com/xml/ns/javaee
          http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
      id="WebApp_ID" version="2.5"&gt;
  
  &lt;servlet&gt;
      &lt;servlet-name&gt;DispatcherServlet&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
      &lt;init-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;/WEB-INF/servlet-context.xml&lt;/param-value&gt;
      &lt;/init-param&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
  &lt;/servlet&gt;
  
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;DispatcherServlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  
  &lt;/web-app&gt;
  </code></pre>
  
  <p>... while my <code>servlet-context.xml</code> defines:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans
      xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:mvc="http://www.springframework.org/schema/mvc"
      xmlns:util="http://www.springframework.org/schema/util"
      xsi:schemaLocation="
          http://www.springframework.org/schema/mvc
          http://www.springframework.org/schema/mvc/spring-mvc.xsd
          http://www.springframework.org/schema/beans
          http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/context
          http://www.springframework.org/schema/context/spring-context.xsd
          http://www.springframework.org/schema/util
          http://www.springframework.org/schema/util/spring-util.xsd"&gt;
  
  &lt;import resource="mongo-context.xml"/&gt;
  
  &lt;context:component-scan base-package="com.moonlight42.sampleserver.model" /&gt;
  
  &lt;mvc:annotation-driven /&gt;
  
  &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
      &lt;property name="prefix" value="/WEB-INF/jsp/" /&gt;
      &lt;property name="suffix" value=".jsp" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="jsonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"&gt;
      &lt;property name="prefixJson" value="false"/&gt;
      &lt;property name="supportedMediaTypes" value="application/json"/&gt;
  &lt;/bean&gt;
  
  &lt;bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"&gt;
      &lt;property name="messageConverters"&gt;
          &lt;util:list id="beanList"&gt;
              &lt;ref bean="jsonHttpMessageConverter"/&gt;
          &lt;/util:list&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>Thanks in advance.</p>