我尝试使用mave-jaxb2插件和JAXB 2-基础简化插件将XSD转换为JAXB类。
pom.xml中的配置可在此帖子中使用。
sample.xsd (复杂选择类型)
<xs:complexType name="doclist">
<xs:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="document1" type="type1">
<xs:annotation>
<xs:appinfo>
<simplify:as-reference-property/>
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="document2" type="type2">
</xs:element>
</xs:choice>
</xs:sequence>
<xs:attribute name="heading" type="xs:string" />
</xs:complexType>
但是,生成的JAXB类具有aOrB引用。
@XmlElements({
@XmlElement(name = "document1", type = Type1.class),
@XmlElement(name = "document2", type = Type2.class)
})
protected List<Object> document1OrDocument2;
发布于 2016-01-11 16:20:37
您有一个elements
属性,所以必须将注释放在xs:choice
上,而不是放在xs:element
上。请看文献资料。
而且您很可能希望使用<simplify:as-element-property/>
。
https://stackoverflow.com/questions/34704757
复制相似问题