JAXB UnMarshall 集合元素顺序
假设我有以下 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);
...
现在我找不到任何描述这些元素的顺序的文档。 在我的应用程序中,XML 文件中的顺序与 java 对象中的顺序相同非常重要。我试图在源代码中查找它,但很难理解。我希望有人能在这方面帮助我。谢谢。
库库
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于对应于 List 属性的元素,List 中的顺序将与 XML 文档中的顺序匹配。
有关 JAXB 和集合属性的更多信息,请参阅:
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: