title: JAXBElement over an ArrayList?
body: <p>How to marshall a List of JAXBElement ?</p>
  
  <p>I've got one POJO I cannot annotate, for instance:</p>
  
  <pre><code>public class APojo {
  
  private String aString;
  
  public APojo() { 
      super(); 
  }
  
  public String getAString() {
      return aString;
  }
  
  public void setAString(String aString) {
      this.aString = aString;
  }
  }
  </code></pre>
  
  <p>So I'm doing this</p>
  
  <pre><code>APojo aPojo = new APojo();
  aPojo.setaString("a string");       
  JAXBElement&lt;APojo&gt; aJAXBedPojo = new JAXBElement&lt;APojo&gt;(new QName("apojo"), APojo.class, aPojo);
  </code></pre>
  
  <p>Which is correctly being marshaled.</p>
  
  <p>However</p>
  
  <pre><code>List&lt;JAXBElement&lt;APojo&gt;&gt; list = new ArrayList&lt;JAXBElement&lt;APojo&gt;&gt;();
  </code></pre>
  
  <p>Is not working: when I' doing this</p>
  
  <pre><code>JAXBContext context = JAXBContext.newInstance(APojo.class, ArrayList.class);
  Marshaller m = context.createMarshaller();
  m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
  m.marshal(list, System.out);
  </code></pre>
  
  <p>The runtime raises:</p>
  
  <pre><code>[com.sun.istack.internal.SAXException2: unable to marshal type "java.util.ArrayList" as an element because it is missing an @XmlRootElement annotation]
  </code></pre>
  
  <p>Which is normal since ArrayList is not annotated.</p>
  
  <p>I know I can create a wrapper around ArrayList and annotate it with a @XmlRootElement so I can marshall this wrapper.</p>
  
  <p>I'm looking for a solution without such a wrapper. Is it possible to create a JAXBElement with T being an ArrayList ? Or something similar ?</p>