Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAXB UnMarshall Collection element order

lets say i have the following XML

<?xml version="1.0" encoding="utf-8"?>
<names>
    <name first="John" last="Doe"/>
    <name first="Jane" last="Doe"/>
    ...
</names>

This is my code:

final JAXBContext context = JAXBContext.newInstance(Names.class);
final Unmarshaller um = context.createUnmarshaller();
final InputStream in = new FileInputStream(file);
final Reader reader = new InputStreamReader(in, Charset.forName("UTF-8"));
final Names namesList = (Names) um.unmarshal(reader);
...

Now i could not find any documentation describing in which order these elements will be. In my application it is important that the order which is in my XML file will be the same in the java object. I tried to look it up in the source but it was very difficult to understand. I hope somebody can help me on this one. Thanks.

kuku

like image 268
kukudas Avatar asked Oct 12 '22 13:10

kukudas


1 Answers

For elements that correspond to a List property the order in the List will match the order from the XML document.

For more information on JAXB and collection properties see:

  • http://bdoughan.blogspot.com/2010/09/jaxb-collection-properties.html
like image 196
bdoughan Avatar answered Oct 15 '22 09:10

bdoughan