Q:

Additional XML-Entitiy to surround List with Java JAXB

I have an Class, which looks like this:
public class X implements Serializable {
    private ArrayList<listElements> listElements;
    //...

    @XmlElement(name = "listelement")
    public ArrayList<listElements> getListElements() {
        return this.listElements;
    }

    public void setListElements(ArrayList<ListElement> listElements) {
        this.listElements = listElements;
    }

    //..

}
If i marshal an instance into XML with JAXB, it looks like this:
<X>
    <listelement name = "listelement1">
        ...
    </listelement>
    <listelement name = "listelement2">
    ...
    </listelement>
</X>

But i would like to surround the listelements with an additional entity like this:
<X>
<listelements>
     <listelement name = "listelement1">
    ...
    </listelement>
        <listelement name = "listelement2">
        ...
        </listelement>
    </listelements>
</X>

How can i do this?

A:

You can use the @XmlElementWrapper annotation to add a grouping element.
@XmlElementWrapper(name = "listelements")
@XmlElement(name = "listelement")
public ArrayList<listElements> getListElements() {
    return this.listElements;
}

