Does JAXB always ignore 'extra' elements not specified in @XmlType/propOrder?
java, jaxb, xml
Solution
Some JAXB (JSR-222) implementations will complain if there are properties mapped to XML elements that are not included in the `propOrder`. `propOder` on `@XmlType` is not used to control which elements are included/excluded.
Options for Excluding Properties
- If you want to exclude less than half of the properties then I would suggest marking the ones you wish to exclude with `@XmlTransient`.
- If you wish to exclude more than half of the properties then I would suggest using `@XmlAccessorType(XmlAccessType.NONE)` and annotating the properties you wish to include.
For More Information
- http://blog.bdoughan.com/2012/04/jaxb-and-unmapped-properties.html
Problem
If I have a class annotated with `@XmlType(name = "someDTO", propOrder = { "firstField", "secondField", })` but the XML (from a SOAP response, say) looks like `<return><firstField>a</firstField><secondField>b</secondField><thirdField>c</thirdField></return>` My object will still get firstField and secondField populated, and thirdField is ignored. Why is this? Will this always be the case? Is there a way to prevent object creation if extra fields are present?