title: How to use JAXB to marshall/unmarshall a collection of MyBean
body: <p>I have a MyBean annotated</p>
  
  <pre><code>@XmlRootElement
  public class MyBean ...
  </code></pre>
  
  <p>Marshalling/Unmarshalling MyBean w/o problems, e.g.</p>
  
  <pre><code>JAXBContext jaxbCtx = JAXBContext.newInstance(MyBean.class);
  Marshaller m = jaxbCtx.createMarshaller();
  m.marshal(myBean, writer);
  </code></pre>
  
  <p>How can I use JAXB to marshall/unmarshall a Collection or List?</p>
  
  <p>My attempt results in this error:</p>
  
  <pre><code>javax.xml.bind.MarshalException
   - with linked exception:
  [com.sun.istack.internal.SAXException2: unable to marshal type "java.util.ArrayList" as an element because it is missing an @XmlRootElement annotation]
      at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:304)
      at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:230)
  </code></pre>