It seems the latest JAX-RS can handle methods returning java.util.List as the XMLRootElement but normal JAXB cannot. I would like to mimic what CXF and Jersey are doing.
In other words I would like to Marshal a List and just like CXF and Jersey do. Normally if you try to marshal a list with JAXB you get the Root Element exception. How do I get around this with out having to make a wrapping object?
EDIT: Thanks for the many answers but I'm very familiar with the @XmlElementWrapper but that does not even come close to simulating what JAX-RS is doing.
JAX-RS does this:
@XmlRootElement(name="dog")
public class Dog {
private String name;
public String getName() { return this.name; }
//Setter also
}
Now if I serialize a list of dogs:
serialize(List<Dog> dogs);
XML should be (what JAX-RS does):
<dogs>
<dog><name>Rascal</name></dog>
</dogs>
So you can see I don't want to have to make a wrapper object for every single domain object.