Question

Lets say these are these objects.

@XmlRootElement
@XmlAccessorType(XmlAccessType.PROPERTY)
public class Root{

    private Collection<Item> items;

    @XmlElement(name="item")
    @XmlElementWrapper(name="items")
    public void setItems(Collection<Item> items){
        this.items = items
    }
}

and

@XmlRootElement
@XmlAccessorType(XmlAccessType.PROPERTY)
public class Item{

    private Collection<Item> items;

    @XmlElement(name="item")
    public void setItems(Collection<Item> items){
        this.items = items
    }
}

I can unmarshall xml files with a structure like this example.

<root>
    <items>
        <item>
            <item>
                <item></item>
                <item></item>
            </item>
            <item></item>
            <item></item>
        </item>
        <item></item>
        <item></item>
    <items>
</root>

The actual question is. When the unmarshaller calls Root.setItems(items) is it guaranteed that every property of each Item from this Collection is fully initialized? Is it possible to change the behavior how the unmarshaller builds the object graph (from TOP to BOTTOM or from BOTTOM to TOP)?

Thanks in advance.

Was it helpful?

Solution

Answers to Your Questions

The actual question is. When the unmarshaller calls Root.setItems(items) is it guaranteed that every property of each Item from this Collection is fully initialized?

Yes,

Is it possible to change the behavior how the unmarshaller builds the object graph (from TOP to BOTTOM or from BOTTOM to TOP)?

No

Why JAXB Works this Way

JAXB (JSR-222) implementations are going to leverage SAX or StAX parsers to efficiently process the XML. These parsers do a depth first traversal of the XML document. Because of this JAXB is going to populate objects the same way. The object corresponding to the first item in a collection is going to be fully processed before JAXB even knows that there is a second item in the collection to be processed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top