jaxb2 simplify plugin elements not simplified

China☆狼群 提交于 2019-12-13 05:26:16

问题


I have tried to convert XSD to JAXB classes using mave-jaxb2 plugin and jaxb2-basics simplify plugin.

The configuration in pom.xml is available in this post

sample.xsd (complex choice type)

<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> 

However the generated JAXB classes have aOrB references.

   @XmlElements({
        @XmlElement(name = "document1", type = Type1.class),
        @XmlElement(name = "document2", type = Type2.class)
    })
    protected List<Object> document1OrDocument2;

回答1:


You have an elements property so you have to place your annotation on the xs:choice, not on the xs:element. Please see the documentation.

And you most probably want to use <simplify:as-element-property/>.



来源:https://stackoverflow.com/questions/34704757/jaxb2-simplify-plugin-elements-not-simplified

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!