I have a bunch of JAXB annotated classes that have a field in common, so I moved that field to a super class, like this
public class Base {
protected SomeType commonField;
}
@XmlRootElement(name = "foo") @XmlType(propOrder = { "commonField", "fooField" })
public class Foo extends Base {
private SomeOtherType fooField;
}
@XmlRootElemen开发者_JAVA百科t(name = "bar") @XmlType(propOrder = { "commonField", "barField" })
public class Bar extends Base {
private SomeOtherType barField;
}
Now whenever I marshall one of Foo
or Bar
I get an IllegalAnnotationException
complaining about commonField
being listed in propOrder
but not present in the class. Removing it from the propOrder
annotation everything works fine, but I thougt I was supposed to list all of the mapped fields. What am I missing?
The fields/properties from the inherited class will always appear before the fields/properties on the child classes. This means that by default you can not specify them in the propOrder
on the child type. If however you mark the parent class as @XmlTransient
the fields/properties will be treated as belonging to the child classes and can be included in the propOrder
.
- http://bdoughan.blogspot.com/2011/06/ignoring-inheritance-with-xmltransient.html
精彩评论