I'm fairly new to JAXB and am eager to learn more about it. What I've noticed is that when marshalling, the XML representation of the objects from an array and list are the identical.
What I'm interested in finding out is how JAXB treats the two data structures when un/marshalling and if it's better to standardize it to use one over the other? If so, what is the difference between the two (performance-wise, etc.)? Also, what should I consider when choosing a container for my objects?
Any information will be appreciated. Thank you!
XOM, JDOM, dom4j, etc. etc. Projects like Castor and Apache XMLBeans predate JAXB, so you could have a look at those. Ulf Dittmer wrote: XOM, JDOM, dom4j, etc.
The JAXB Marshaller interface is responsible for governing the process of serializing Java content trees i.e. Java objects to XML data. This marshalling to XML can be done to variety of output targets.
The Unmarshaller class governs the process of deserializing XML data into newly created Java content trees, optionally validating the XML data as it is unmarshalled. It provides an overloading of unmarshal methods for many different input kinds.
In XML representation both arrays and List
s have the same form. When unmarshaling an XML, JAXB will choose the type you have in your Java class.
It's possible to unmarshal a collection to an array which was marshalled from a List
and vice versa.
Both arrays and List
s have their pros and cons. Use what is better for your purpose. In general List
are easier to use because you have utility methods like List.contains()
, but List
s cannot be used for primitive types. Arrays can be faster but are less flexible.
It's really up to you which you use and which is better for you.
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