开发者

JAXB UnMarshall Collection element order

开发者 https://www.devze.com 2023-02-16 13:47 出处:网络
lets say i have the following XML <?xml version=\"1.0\" encoding=\"utf-8\"?> <names> <name first=\"John\" last=\"Doe\"/>

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"/>
    .开发者_JAVA技巧..
</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


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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号