JAXB unmarshal list element by element



I need some help with unmarshalling some XML. Especially with unmarshalling a list of elements. See the following example:



@XmlRootElement(name="element")
public class Element
{
private ArrayList<Element> children;

public ArrayList<Element> getChildren() {
return children;
}

@XmlElementWrapper(name = "children")
@XmlElement(name = "element")
public void setChildren(ArrayList<Element> children) {
this.children = children;
}
}


This will unmarshal the list perfectly, BUT what I need is an unmarshalling of all children element by element and adding them through some "addElement" method:



public void addElement(Element element) {
children.add(element)
}


Is this possible with some simple annotation magic? Of course I could loop through the elements and call "addElement".


No comments:

Post a Comment