jaxb2-maven-plugin是否与具有简化扩展功能的jaxb绑定兼容?

问题描述

我正在尝试使用org.codehaus.mojo:jaxb2-maven-plugin:2.5.0从xsd模式中生成Java对象。 我不允许修改架构,因为它来自供应商。

我正在尝试通过jaxb绑定的选择来简化complexType。 这是架构

<xs:complexType name="IdentificationType">
        <xs:choice>
            <xs:sequence>
                <xs:element name="Identifier" nillable="false">
                    <xs:simpleType>
                        <xs:restriction base="IdentiferType">
                            <xs:minLength value="2"/>
                        </xs:restriction>
                    </xs:simpleType>
                </xs:element>
                <xs:element name="ProductNumber" type="ProductNumberType" nillable="false" minOccurs="0">
                </xs:element>
            </xs:sequence>
            <xs:element name="ProductNumber" type="ProductNumberType" nillable="false">
            </xs:element>
        </xs:choice>
    </xs:complexType>

这是我的Maven插件

 <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>jaxb2-maven-plugin</artifactId>
        <version>2.5.0</version>
     
        <executions>
            <execution>
                <id>product-schema</id>
                <goals>
                    <goal>xjc</goal>
                </goals>
                <configuration>
                    <clearOutputDir>false</clearOutputDir>
                    <xsdpathWithinArtifact>xsd</xsdpathWithinArtifact>
                    <addGeneratedAnnotation>true</addGeneratedAnnotation>
                    <verbose>true</verbose>
                    <target>2.1</target>
                    <extension>true</extension>
                    <xjbSources>
                        <xjbSource>${basedir}/src/main/resources/xjb/mybinding.xjb</xjbSource>
                    </xjbSources>
                    <sources>
                        <source>src/main/resources/schema</source>
                    </sources>
                </configuration>
            </execution>
        </executions>
    </plugin>

还有我的绑定

<?xml version="1.0" encoding="UTF-8"?>
<bindings version="2.1"
          xmlns="http://java.sun.com/xml/ns/jaxb"
          xmlns:xs="http://www.w3.org/2001/XMLSchema"
          xmlns:xsd="http://www.w3.org/2001/XMLSchema"
          xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
          xmlns:simplify="http://jaxb2-commons.dev.java.net/basic/simplify"
          extensionBindingPrefixes="xjc simplify">

    <bindings schemaLocation="../common.xsd"
              node="xs:complexType[@name='IdentificationType']">
        <simplify:as-element-property/>
    </bindings>
</bindings>

我有一个错误

org.xml.sax.SAXParseException: Unsupported binding namespace "http://jaxb2-commons.dev.java.net/basic/simplify". Perhaps you meant "http://jaxb.dev.java.net/plugin/code-injector"?

如果不进行简化,结果将是这样

@XmlElementRefs({
        @XmlElementRef(name = "Identifier",namespace = "http://mynamespce.net/1",type = JAXBElement.class),@XmlElementRef(name = "ProductNumber",type = JAXBElement.class)
    })
    @Generated(value = "com.sun.tools.xjc.Driver",date = "2020-09-08T10:10:41+10:00",comments = "JAXB RI v2.3.2")
    protected List<JAXBElement<? extends Serializable>> content;

我希望Identifier和ProductNumber是一个元素,而不是JAXBElement。像这样的东西

@XmlElement(name = "Identifier")
    protected String Identifier;
    @XmlElement(name = "ProductNumber")
    protected ProductNumberType productNumberInSequence;

如何使用jaxb2-maven-plugin实现此目标?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)