I'm un-marshalling some XML to a string using JAXB. However the order of attributes is not the same as the original XML when running our build scripts via Maven. This is failing some unit-tests which pass perfectly fine in Eclipse.
Any ideas why this would happen? Lots of similar questions here but hard to find a solid answer. :)
The order in which attributes appear in XML is not significant while the order in which elements occur is. JAXB like most XML technologies does not guarantee the order in which the attributes will appear. Your unit tests will need to account for this.
Note
When using Unmarshaller
& Marshaller
the output XML is based on the mapping metadata and not the ordering of the input XML. The metadata allows you to specify the ordering of elements but not attributes. You can use JAXB's Binder
to marshal into an existing document (DOM).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With