JAXB @XmlElements顺序

隐藏的用户
@XmlElements({
     @XmlElement(name = "house", type = House.class),
     @XmlElement(name = "error", type = Error.class),
     @XmlElement(name = "message", type = Message.class),
     @XmlElement(name = "animal", type = Animal.class)     
 })
protected List<RootObject> root;

其中RootObject是House,Error,Message,Animal的超类

root.add(new Animal());
root.add(new Message());
root.add(new Animal());
root.add(new House());
//Prints to xml
<animal/>
<message/>
<animal/>
<house/>

但需要按内部声明的顺序 @XmlElements({})

<house/>
<message/>
<animal/>
<animal/>
博多安

什么@XmlElements

@XmlElements对应choice于XML Schema中结构。一个属性对应于多个元素(请参阅:http : //blog.bdoughan.com/2010/10/jaxb-and-xsd-choice-xmlelements.html

托收单

JAXB实现将兑现将项目添加到中的顺序List这与您看到的行为相匹配。

获取所需的订单

  1. 您可以List按照希望它们显示在XML文档中的顺序将它们添加到中。
  2. 您可以具有与每个元素相对应的单独属性,然后使用propOrderon@XmlType对输出进行排序(请参阅:http : //blog.bdoughan.com/2012/02/jaxbs-xmltype-and-proporder.html
  3. List对JAXBbeforeMarshal事件属性进行排序

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章