title: posting xml to a spring REST endpoint is not getting unmarshalled into the relevant Java object
body: <p>I have a project where xsd are given. I use the xjc compiler to generate the Java classes. And then I annotate the class with XmlRootElement attribute. I have configured the sevlet with the Jaxb2 marshalling/unmarshalling bean in the AnnotationMethodHandlerAdapter. when I send an xml, without the namespaces, I get the 415 error. </p>
  
  <p>The source code is as follows
  file - web.xml</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_3_0.xsd" id="WebApp_ID" version="3.0"&gt;
    &lt;display-name&gt;Test&lt;/display-name&gt;
    &lt;servlet&gt;
      &lt;servlet-name&gt;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;dispatcher&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/rest/*&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>file - dispatcher-servlet.xml</p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
      xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
      xmlns:mvc="http://www.springframework.org/schema/mvc"
      xsi:schemaLocation="
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
          http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
          http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd"
      xmlns:oxm="http://www.springframework.org/schema/oxm"&gt;
  
      &lt;context:component-scan base-package="com.test.endpoints" /&gt;
  
      &lt;tx:annotation-driven /&gt;
  
      &lt;bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"&gt;
          &lt;property name="messageConverters"&gt;
            &lt;list&gt; 
              &lt;ref bean="marshallingHttpMessageConverter"/&gt;
            &lt;/list&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
      &lt;bean id="marshallingHttpMessageConverter" 
            class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter"&gt;
             &lt;constructor-arg ref="jaxb2Marshaller" /&gt;
      &lt;/bean&gt; 
      &lt;bean id="jaxb2Marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"&gt;
          &lt;property name="classesToBeBound"&gt;
              &lt;list&gt;
                  &lt;value&gt;com.test.users.User&lt;/value&gt;
                  &lt;value&gt;com.test.users.Users&lt;/value&gt;
              &lt;/list&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
      &lt;!-- Should be defined last! --&gt;
  &lt;!--    &lt;mvc:annotation-driven /&gt;--&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>file - user.xsd
      
      </p>
  
  <pre><code>    &lt;element name="users"&gt;
          &lt;complexType&gt;
              &lt;sequence&gt;
                  &lt;element name="user" type="tns:user" minOccurs="0"
                      maxOccurs="unbounded" /&gt;
              &lt;/sequence&gt;
          &lt;/complexType&gt;
      &lt;/element&gt;
      &lt;complexType name="user"&gt;
          &lt;sequence&gt;
              &lt;element name="id" type="int" /&gt;            
              &lt;element name="email" type="string"&gt;&lt;/element&gt;
              &lt;element name="first_name" type="string"&gt;&lt;/element&gt;
              &lt;element name="last_name" type="string"&gt;&lt;/element&gt;          
          &lt;/sequence&gt;
      &lt;/complexType&gt;
  &lt;/schema&gt;
  </code></pre>
  
  <p>Used this command to generate the Java classes for the above xsd.</p>
  
  <pre><code>xjc -p com.test.users ..\xsd\user.xsd
  </code></pre>
  
  <p>Output of this command is</p>
  
  <pre><code>parsing a schema...
  compiling a schema...
  com\test\users\ObjectFactory.java
  com\test\users\User.java
  com\test\users\Users.java
  com\test\users\package-info.java
  </code></pre>
  
  <p>Annotated User.java with @XmlRootElement(name="user").</p>
  
  <p>file - UserService.java</p>
  
  <pre><code>package com.test.endpoints;
  
  import org.springframework.stereotype.Controller;
  import org.springframework.web.bind.annotation.RequestBody;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.bind.annotation.ResponseBody;
  
  import com.test.users.User;
  
  @Controller
  @RequestMapping("/users")
  public class UserService {
      @RequestMapping(value="/new", method=RequestMethod.POST)
      @ResponseBody
      public User createUser(@RequestBody User user) {
          System.out.println(user.getFirstName());
  
          return user;
      }
  }
  </code></pre>
  
  <p>Tested the REST api with this curl command</p>
  
  <pre><code>curl -X POST -HContent-type:application/xml -HAccept:application/xml  --data "&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;user&gt;&lt;id&gt;1&lt;/id&gt;&lt;email&gt;email@email.com&lt;/email&gt;&lt;first_name&gt;first_name&lt;/first_name&gt;&lt;last_name&gt;last_name&lt;/last_name&gt;&lt;/user&gt;" http://localhost:8080/Test/rest/users/new
  </code></pre>
  
  <p>Output is</p>
  
  <pre><code>The request sent by the client was syntactically incorrect ()
  </code></pre>
  
  <p>Can somebody please point me where I am going wrong.</p>
  
  <p>Thanks</p>