title: Yet another marshalling exception with JAXB and List<Something>
body: <p>Here is my Request class which holds a generics request: </p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.List;
  import javax.xml.bind.annotation.XmlAccessType;
  import javax.xml.bind.annotation.XmlAccessorType;
  import javax.xml.bind.annotation.XmlAnyElement;
  import javax.xml.bind.annotation.XmlRootElement;
  
  /**
   *
   * @author lorddoskias
   */
  @XmlRootElement
  @XmlAccessorType(XmlAccessType.FIELD)
  public class Request {
  
      private List&lt;StringStringMapEntry&gt; parameters = new ArrayList&lt;StringStringMapEntry&gt;();
      private List&lt;StringStringMapEntry&gt; headers = new ArrayList&lt;StringStringMapEntry&gt;();
      @XmlAnyElement(lax=true)
      private Object requestBody = null;  // this has to reference a JAXB-enabled object
      private String resourcePath;
  
  
      public Request() {
      }
  
      public Object getRequestBody() {
          return requestBody;
      }
  
      public void setRequestBody(Object requestBody) {
          this.requestBody = requestBody;
      }
  </code></pre>
  
  <p>Some parts are omitted for brevity but the essence is there. Then I have the following Sequence class: </p>
  
  <pre><code>import javax.xml.bind.annotation.XmlRootElement;
  
  /**
   *
   * @author lorddoskias
   */
  @XmlRootElement
  public class Sequence {
  
      private String sequenceName;
      private long numReads;
      private int sequenceLength;
  
      public Sequence() {
          /* Required by JAXB */
      }
  
      public Sequence(String name, long numReads, int length) {
          sequenceName = name;
          this.numReads = numReads;
          sequenceLength = length;
      }
  
      public long getNumReads() {
          return numReads;
      }
  
      public void setNumReads(long numReads) {
          this.numReads = numReads;
      }
  
      public int getSequenceLength() {
          return sequenceLength;
      }
  
      public void setSequenceLength(int sequenceLength) {
          this.sequenceLength = sequenceLength;
      }
  
      public String getSequenceName() {
          return sequenceName;
      }
  
      public void setSequenceName(String sequenceName) {
          this.sequenceName = sequenceName;
      }
  }
  </code></pre>
  
  <p>And I do something like that: </p>
  
  <pre><code>List&lt;Sequence&gt; seq = new ArrayList&lt;Sequence&gt;();
          seq.add(seq1);
          seq.add(seq2);
  
          client.insertIndividualStatistics(PostRequest.assemblyIndividualStats(66, seq));
  </code></pre>
  
  <p>Here is the insertIndividualStatistics method: </p>
  
  <pre><code>public static Request assemblyIndividualStats(int stepId, List&lt;Sequence&gt; l) {
  
      Request req = new Request();
      req.setResourcePath("/stats/assembly/individual");
  
      req.addParameter("id", String.valueOf(stepId));
      req.setRequestBody(l);
  
      return req;
  }
  </code></pre>
  
  <p>And when I try to <code>WebResource res = client.resource(bla).path("my-path").post(req);</code>  I get : </p>
  
  <pre><code>Exception in thread "main" com.sun.jersey.api.client.ClientHandlerException: javax.ws.rs.WebApplicationException: javax.xml.bind.MarshalException
   - with linked exception:
  [javax.xml.bind.JAXBException: class uk.org.infectogenomics.model.rest.MySequenceListWrapper nor any of its super class is known to this context.]
  </code></pre>
  
  <p>I thought JAXB supported simple Lists if they weren't a root object? I even tried something different - wrapping the list in a simple JAXB annotated class: </p>
  
  <pre><code>import java.util.List;
  import javax.xml.bind.annotation.XmlElement;
  import javax.xml.bind.annotation.XmlRootElement;
  
  /**
   *
   * @author lorddoskias
   */
  @XmlRootElement
  public class MySequenceListWrapper {
  
      @XmlElement(name = "List")
      private List&lt;Sequence&gt; list;
  
      public MySequenceListWrapper() {/*JAXB requires it */
  
      }
  
      public MySequenceListWrapper(List&lt;Sequence&gt; list) {
          this.list = list;
      }
  
      public List&lt;Sequence&gt; getList() {
          return list;
      }
  }
  </code></pre>
  
  <p>And setting that as the requestBody but then I get a similar exception but instead of it saying that ArrayList is unrecognized it says that MySequenceListWrapper is unrecognized. I've read the article from Blaise Doughan blog and I suspect that at least in the latter case it should work since I have the appropriate XmlAnyElement annotation?</p>