如何告诉JAXB元素的顺序无关紧要? [英] How to tell JAXB that order of elements does not matter?

查看:134
本文介绍了如何告诉JAXB元素的顺序无关紧要?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以告诉JAXB忽略元素的顺序?因此生成XSD将包含所有 -elements而不是序列 -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 ,像这样:

@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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆