title: Passing multiple xml objects to jax-rs service
body: <p>I'm using JAX-RS Jersey and JAXB on my server code to implement services, which I consume from an Android app. I already have the services returning my custom objects in xml format and I can unmarshal them just fine on the client side.
  Now I want to send my custom objects from the client to the server in xml, I wrote a simple test but it fails with error 400.
  This is the service:</p>
  
  <pre><code>@POST
  @Path("/test")
  @Produces(MediaType.TEXT_PLAIN)
  @Consumes(MediaType.APPLICATION_XML)
  public String test(List&lt;Client&gt; clientList, Client client) {
      //do something with clientList and client
      return response;
  }
  </code></pre>
  
  <p>This is the xml I send in the request body:</p>
  
  <pre><code>&lt;clientList&gt;
      &lt;client name="" phone="" address="" /&gt;        
      &lt;client name="" phone="" address="" /&gt;        
  &lt;/clientList&gt;
  &lt;client name="" phone="" address="" /&gt;
  </code></pre>
  
  <p>And here is the client code:</p>
  
  <pre><code>HttpPost httpPost = new HttpPost(url);                
  httpPost.addHeader("Accept", "text/plain");
  httpPost.setHeader("Content-Type", "application/xml");
  httpPost.setEntity(new StringEntity(xmlFromAbove, HTTP.UTF_8));
  HttpResponse response = androidHttpClient.execute(httpPost);
  </code></pre>
  
  <p>If I only put one parameter in the service it works fine, but with more than one it seems that JAXB doesn't know how to unmarshall them.
  Do I have to wrap all the parameters I need in one custom object, or is there simpler way to do it?</p>
  
  <p>I also tried passing the xml strings as FormParams and using the following code to unmarshal it</p>
  
  <pre><code>JAXBContext jc = JAXBContext.newInstance(Client.class);
  Unmarshaller unmarshaller = jc.createUnmarshaller();            
  List&lt;Client&gt; clients = 
      (List&lt;Client&gt;)unmarshaller.unmarshal(new StringReader(clientListXml));
  </code></pre>
  
  <p>But it didn't work either, it throws </p>
  
  <pre><code>javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"clients").  
      Expected elements are &lt;{}client&gt;
  </code></pre>
  
  <p>When I return a List from the service, jaxb marshalls it correctly, without having to wrap the list in a custom object. Do I have to wrap it anyway in order to do the unmarshalling?</p>