Совместим ли jaxb2-maven-plugin с привязкой jaxb с упрощением расширения?

Я пытаюсь создать объект java из схемы xsd с помощью org.codehaus.mojo:jaxb2-maven-plugin:2.5.0. Мне не разрешено изменять схему, так как она от поставщика.

Я пытаюсь упростить complexType выбором с привязкой jaxb. Вот схема

<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", namespace = "http://mynamespce.net/1", 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?

0 ответов

Другие вопросы по тегам