title: Spring Rest JSON Binding
body: <p>I'm trying to create a Restful service with Spring.</p>
  
  <p>A method accepts a "UserContext" object via argument i.e. @RequestBody. </p>
  
  <p>The client sends the JSON object with content-type "application/json". But I get the error "HTTP/1.1 415 Unsupported Media Type".</p>
  
  <p>..even when the client sends a null "{}" JSON object.</p>
  
  <p>My controller:</p>
  
  <pre><code>@Controller
  @RequestMapping(value = "/entityService")
  class RestfulEntityService {
  
    @Resource
    private EntityService entityService;
  
    @ResponseBody
    @RequestMapping(value = "/getListOfEntities", method = RequestMethod.POST)
    public List&lt;Entity&gt; getListOfEntities(@RequestBody UserContext userContext) {
      System.out.println(userContext);
      return null;
    }
  }
  </code></pre>
  
  <p>UserContext.java</p>
  
  <pre><code>public class UserContext {
  
      private Long userId;
  
      private String userName;
  
      private UserAddress userAddress;
  
      private CustomerInfo customerInfo;
  
  }
  </code></pre>
  
  <p>Application context:</p>
  
  <pre class="lang-xml prettyprint-override"><code>  &lt;bean id="xstreamMarshaller" class="org.springframework.oxm.xstream.XStreamMarshaller"/&gt;
    &lt;bean id="xmlMessageConverter"
          class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter"&gt;
      &lt;constructor-arg ref="xstreamMarshaller"/&gt;
      &lt;property name="supportedMediaTypes" value="application/xml"/&gt;
    &lt;/bean&gt;
  
    &lt;bean id="jsonHttpMessageConverter"
          class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"&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="xmlMessageConverter" /&gt;
          &lt;ref bean="jsonHttpMessageConverter"/&gt;
        &lt;/util:list&gt;
      &lt;/property&gt;
    &lt;/bean&gt;
  
    &lt;mvc:annotation-driven/&gt;
  </code></pre>
  
  <p>Struggling with this for a while. Help will be appreciated!</p>