title: Xstream marshaller not unmarshelling xml post body
body: <p>I am trying to create a spring  rest service. My servlet.xml is like following:</p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:util="http://www.springframework.org/schema/util"
  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/mvc
      http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"&gt;
  
      &lt;bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/&gt;
  
  
  &lt;!-- Database Configuration --&gt;
  &lt;import resource="classpath:DataSource.xml"/&gt;
  &lt;import resource="classpath:Hibernate.xml"/&gt;
  
  &lt;!-- Beans Declaration --&gt;
  &lt;import resource="classpath:Employee.xml"/&gt;
  
  &lt;context:component-scan base-package="com.nilenium.service.controller" /&gt;
  
  &lt;mvc: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="jsonConverter"/&gt;
     &lt;ref bean="marshallingHttpMessageConverter"/&gt;
    &lt;/list&gt;
     &lt;/property&gt;
    &lt;/bean&gt;
  
     &lt;bean id="jsonConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"&gt;&lt;/bean&gt;
  
  
    &lt;bean id="xstreamMarshaller" class="org.springframework.oxm.xstream.XStreamMarshaller"&gt;
     &lt;property name="autodetectAnnotations" value="true"/&gt;
     &lt;property name="annotatedClasses"&gt;
      &lt;list&gt;
          &lt;value&gt;com.nilenium.employee.model.Employee&lt;/value&gt;                         
          &lt;value&gt;com.nilenium.employee.model.EmployeeRecord&lt;/value&gt;                           
      &lt;/list&gt;                     
    &lt;/property&gt;
  
  &lt;/bean&gt;
  
      &lt;bean id="marshallingHttpMessageConverter"
        class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter"&gt;
      &lt;property name="marshaller" ref="xstreamMarshaller"/&gt;
      &lt;property name="unmarshaller" ref="xstreamMarshaller"/&gt;
  &lt;/bean&gt;
  
  
  
    &lt;bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"&gt;
   &lt;property name="order" value="1" /&gt;
    &lt;property name="ignoreAcceptHeader" value="true" /&gt;
   &lt;property name="defaultContentType" value="application/json" /&gt;
    &lt;property name="mediaTypes"&gt;
   &lt;map&gt;
   &lt;entry key="json" value="application/json" /&gt;
   &lt;entry key="xml" value="application/xml" /&gt;
   &lt;/map&gt;
   &lt;/property&gt;
  
  &lt;property name="defaultViews"&gt;
   &lt;list&gt;
  &lt;!-- JSON View --&gt;
  &lt;bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" /&gt;
  
  &lt;!-- XML View --&gt;
   &lt;bean class="org.springframework.web.servlet.view.xml.MarshallingView"&gt;
   &lt;constructor-arg&gt;
    &lt;bean class="org.springframework.oxm.xstream.XStreamMarshaller"&gt;
     &lt;property name="autodetectAnnotations" value="true"/&gt;
     &lt;property name="aliases"&gt;
      &lt;props&gt;
       &lt;prop key="employee"&gt;com.nilenium.employee.model.Employee&lt;/prop&gt;
       &lt;prop key="employee"&gt;com.nilenium.employee.model.EmployeeRecord&lt;/prop&gt;
       &lt;/props&gt;
  &lt;/property&gt;
    &lt;/bean&gt;
   &lt;/constructor-arg&gt;
  &lt;/bean&gt;
     &lt;/list&gt;
    &lt;/property&gt;
   &lt;/bean&gt;
  
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>And my model class is like this:</p>
  
  <pre><code>package com.nilenium.employee.model;
  
  import java.io.Serializable;
  
  import org.codehaus.jackson.annotate.JsonProperty;
  import org.codehaus.jackson.map.annotate.JsonRootName;
  
  import com.thoughtworks.xstream.annotations.XStreamAlias;
  
  
  @XStreamAlias("employee")
  
  public class Employee implements Serializable {
  
  private static final long serialVersionUID = 1L;
  
  
  private int employeeId;
  private String employeeName;
  
  public int getEmployeeId() {
      return employeeId;
  }
  
  public void setEmployeeId(int employeeId) {
      this.employeeId = employeeId;
  }
  
  public String getEmployeeName() {
      return employeeName;
  }
  
  public void setEmployeeName(String employeeName) {
      this.employeeName = employeeName;
  }
  
  
  
  public Employee(int employeeId, String employeeName)
  {
      this.employeeId = employeeId;
      this.employeeName = employeeName;
  
  }
  public Employee() {
  }
  }
  </code></pre>
  
  <p>My service controller class is like this:</p>
  
  <pre><code>package com.nilenium.service.controller;
  
  import java.util.List;
  import javax.servlet.http.HttpServletResponse;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.ModelMap;
  import org.springframework.web.bind.annotation.ExceptionHandler;
  import org.springframework.web.bind.annotation.PathVariable;
  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.nilenium.employee.bo.EmployeeBo;
  import com.nilenium.employee.model.Employee;
  import com.nilenium.employee.model.EmployeeRecord;
  
  @Controller
  @RequestMapping("/Service")
  public class NileniumServiceController {
  
  @Autowired
  private EmployeeBo employeeBo;
  
  @ExceptionHandler
   public String exceptionHandler(Exception e){
      return "serviceError"; 
   }
  
  @RequestMapping(value =  "employeeId/{employeeId}", method = RequestMethod.GET, headers = "Accept=application/xml, application/json")
  public Employee getEmployeeName(@PathVariable int employeeId,
          HttpServletResponse resp,
          ModelMap model) {
  //      System.out.println("Emp Name : " + employeeName);
      Employee empReturned = new Employee();
      empReturned.setEmployeeId(employeeId);
      empReturned.setEmployeeName("Demo Name");
  
      return empReturned;
  
  }
  
  @RequestMapping(value = "/employees", method = RequestMethod.GET, headers = "Accept=application/xml, application/json")
  public EmployeeRecord getAllEmployeeDetails(HttpServletResponse resp,
          ModelMap model) {
  
      List&lt;Employee&gt; empListReturned = employeeBo.getAllEmployee();
      EmployeeRecord eRecords = new EmployeeRecord();
      eRecords.setEmployeeList(empListReturned);
      return eRecords;
  }
  
  @RequestMapping(value = "/storeemployee",method = RequestMethod.POST, headers = {"Accept=text/xml, application/json"})
  public Employee storeEmpRecord(@RequestBody Employee employee,HttpServletResponse resp,
          ModelMap model)
  {
      System.out.println("Emp Id received : "+employee.getEmployeeId());
      System.out.println("Emp Name received : "+employee.getEmployeeName());
  //      Employee empReturned = employeeBo.findByEmployeeId(1);
  
  
      return employee;
  }
  
  }
  </code></pre>
  
  <p>When I am trying to post an xml to the <code>storeEmpRecord</code> method xstream marshaller is not able to convert the xml request to respective object (<code>Employee</code> object).</p>
  
  <p>My test client is like this:</p>
  
  <pre><code>package com.nilenium.test;
  
  import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.io.UnsupportedEncodingException;
  import java.net.URISyntaxException;
  
  import org.apache.http.HttpEntity;
  import org.apache.http.HttpException;
  import org.apache.http.HttpResponse;
  import org.apache.http.client.HttpClient;
  import org.apache.http.client.methods.HttpPost;
  import org.apache.http.entity.StringEntity;
  import org.apache.http.impl.client.DefaultHttpClient;
  import org.springframework.aop.framework.adapter.DefaultAdvisorAdapterRegistry;
  
  import com.nilenium.employee.model.Employee;
  import com.thoughtworks.xstream.XStream;
  import com.thoughtworks.xstream.io.xml.DomDriver;
  
  public class RestPostTest {
  public static void main(String[] args) {
  Employee emp = new Employee();
  emp.setEmployeeId(1);
  emp.setEmployeeName("Nilalohita");
  
  XStream xStream = new XStream(new DomDriver());
  xStream.alias("employee", Employee.class);
  System.out.println(xStream.toXML(emp));
  String xmlBody = xStream.toXML(emp);
  HttpClient client = new DefaultHttpClient();
  String jsonDemo = "{\"employeeId\":2,\"employeeName\":\"He-Man\"}";
  try {
      HttpPost post = new  HttpPost("http://localhost:8080/SampleMaven/Service/storeemployee");
  //      post.addHeader("Accept", "application/json");
  //      post.addHeader("Content-Type", "application/json");
  
      post.addHeader("Accept", "application/xml");
      post.addHeader("Content-Type", "application/xml");
  
      StringEntity entity = new StringEntity(xmlBody, "UTF-8");
  //      entity.setContentType("application/json");
      entity.setContentType("application/xml");
      post.setEntity(entity);
  
      HttpResponse response = client.execute(post);
  
      BufferedReader rd = new BufferedReader(new   InputStreamReader(response.getEntity().getContent()));
        String line = "";
        while ((line = rd.readLine()) != null) {
         System.out.println(line);
        }
  
  
  } catch (URISyntaxException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
  } catch (UnsupportedEncodingException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
  } catch (HttpException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
  } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
  }
  }
  }
  </code></pre>
  
  <p>Please let me know if i am doing something wrong. The same thing is working for jaxb using <code>@XMLroot</code> for Employee class instead of <code>@XStreamAlias("employee")</code>.</p>
  
  <p>I am getting the following error. the full stack trace is like this</p>
  
  <pre><code>   Caused by:&lt;/h3&gt;&lt;pre&gt;javax.servlet.ServletException: Unable to locate object to be marshalled in model: {}
    at  org.springframework.web.servlet.view.xml.MarshallingView.renderMergedOutputModel(MarshallingView.java:100)
    at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
  at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1047)
  at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817)
  at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
  at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
  at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
  at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
  at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
  at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
  at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
  at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:726)
  at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
  at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:206)
  at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
  at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
  at org.mortbay.jetty.Server.handle(Server.java:324)
  at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
  at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)
  at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:648)
  at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:205)
  at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
  at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
  at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
  </code></pre>