如何告诉 JAXB 元素的顺序无关紧要? [英] How to tell JAXB that order of elements does not matter?
本文介绍了如何告诉 JAXB 元素的顺序无关紧要?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以告诉 JAXB 忽略元素的顺序?这样生成的 XSD 将包含 all
-elements 而不是 sequence
-elements?
Is it possible to tell JAXB to ignore the order of elements? So that the generate XSD will contain all
-elements instead of sequence
-elements?
推荐答案
添加 XmlType
注释到带有空 propOrder
的类,如下所示:
Add an XmlType
annotation to the class with an empty propOrder
, like this:
@XmlType(propOrder={})
public class MyClass{
String username;
String street;
String address;
}
然后它会生成一个 xs:all
(它是无序的)而不是一个序列.
It will then generate an xs:all
(which is unordered) instead of a sequence.
<xs:complexType name="MyClass">
<xs:all>
<xs:element name="username" type="xs:string" minOccurs="0"/>
<xs:element name="street" type="xs:string" minOccurs="0"/>
<xs:element name="address" type="xs:string" minOccurs="0"/>
</xs:all>
</xs:complexType>
这篇关于如何告诉 JAXB 元素的顺序无关紧要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文