@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
。这与您看到的行为相匹配。
List
按照希望它们显示在XML文档中的顺序将它们添加到中。propOrder
on@XmlType
对输出进行排序(请参阅:http : //blog.bdoughan.com/2012/02/jaxbs-xmltype-and-proporder.html)List
对JAXBbeforeMarshal
事件的属性进行排序。本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句