简体   繁体   中英

JAXB : Order of elements in multiple lists

I have two lists in my root element object. List<Person> persons and List<Address> addresses . When i marshall this , it prints first all the person and then all the addresses . I want to print it one by one . Person then address , person and address and so on . How can i do that in JAXB ?

You can use @XmlElements or @XmlElementRefs .

Assuming neither Person extends Address nor vice versa, the code will be something like:

@XmlElements {
    @XmlElement(name="Person", type=Person.class),
    @XmlElement(name="Address", type=Address.class)
}
private List<Object> personOrAddress;

However consider remodelling it as a special type like PointOfContact so that you don't have a heterogeneous property.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM