Lets say i have class
@XmlType(propOrder = {
"one",
"two"
})
@XmlRootElement(name = "search")
public class Search {
protected One one;
protected Two two;
//getters & setters
}
and i wanted a class that extends this class
e.g.
@XmlType(propOrder = {
"three"
})
@XmlRootElement(name = "searchExtended")
public class SearchExtended extends Search {
protected Three three;
//getters & setters
}
how do you declare the propOrder correctly, i have tried this before and it did not use the order i thought it would. How is this handled by annotations? / how should you be declaring this across extended classes?
The parents properties will be marshalled based on their specified ordering before the child properties. You can include the properties from the parent class in the
propOrderof the child class if you annotate the parent class with@XmlTransient.UPDATE
No, setting
@XmlTransienton a class removes it from the classes that JAXB considers mapped. The reason that JAXB marhals the properties of the super class before the properties of the subclass is to match the rules of XML schema. When yourSearchclass is not marked with@XmlTransientthe corresponding XML schema is the following. According to the XML schema rules in order for a element of typesearchExtendedto be valid the elements from the super type must occur before any elements defined in the subtype.You can see the XML schema that corresponds to your JAXB model by running the following code: