JAXB UnMarshall集合元素顺序 [英] JAXB UnMarshall Collection element order
问题描述
让我说我有以下XML
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>
这是我的代码:
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);
...
$ b $ p现在我找不到任何文档描述这些元素是。
在我的应用程序中,重要的是,在我的XML文件中的顺序将在java对象中是相同的。我试图在源中查找它,但它是非常难以理解。我希望有人能在这一个帮助我。非常感谢。
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
推荐答案
属性,List中的顺序将匹配来自XML文档的顺序。
For elements that correspond to a List property the order in the List will match the order from the XML document.
有关JAXB和集合属性的详细信息,请参阅:
For more information on JAXB and collection properties see:
- http://bdoughan.blogspot.com/2010/09/jaxb-collection-properties.html
这篇关于JAXB UnMarshall集合元素顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!