Santi
Santi

Reputation: 87

embedded bindings is not working with jaxb xjc 3.0.0

I am using jaxb 3.0.0 (xjc.sh) to create Java Classes but for some reason, it is NOT honoring embedded bindings. The same thing works fine with jaxb 2.3.1

$ pwd /c/jaxb-ri-3.0.0/jaxb-ri/bin

$ ./xjc.sh Validation.xsd

It is creating ApiValidator.java where as I expect it to NOT create a new one rather than refer to the one which I put as embedded binding.

$ cat Validation.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="a/model"
           xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="2.0"
           xmlns:tns="a/model" elementFormDefault="qualified">

    <xs:attribute name="Description" type="xs:string"/>
    <xs:attribute name="Required" type="xs:boolean"/>

    <xs:complexType name="ValidationAction">
        <xs:sequence>
            <xs:element name="api" type="xs:string" tns:Description="Indicates the validation API"/>
            <xs:element name="method" type="xs:string" tns:Description="Indicates the validation method"/>
            <xs:element name="beanName" type="xs:string" tns:Description="Validation bean name"/>
            <xs:element name="validationClass" type="xs:string" tns:Description="Validation class type"/>
            <xs:element name="idOwner" type="xs:int" tns:Description="Indicates the owner associated with the validation"/>
            <xs:element name="valid" type="xs:boolean" tns:Description="Indicates if validation is valid"/>
            <xs:element name="validator" type="tns:ApiValidator" minOccurs="0" maxOccurs="1"
                        tns:Description="Reference to the API validator"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="ApiValidator">
        <xs:annotation>
            <xs:appinfo>
                <jaxb:bindings node="//xs:complexType[@name='ApiValidator']">
                    <jaxb:class ref="a.ApiValidator"/>
                </jaxb:bindings>
            </xs:appinfo>
        </xs:annotation>
    </xs:complexType>

</xs:schema>

Whereas if I do the same with 2.3.1 version, $ ./xjc.sh Validation.xsd Java major version: 8 parsing a schema... compiling a schema...

I need to use the 3.0.0 version as it generates jakarta namespace. Please suggest why is it not working and how to fix it?

This behavior is same with below-mentioned xml:

$ cat V.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="a/model"
           xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="2.0"
           xmlns:tns="a/model" elementFormDefault="qualified">

    <xs:attribute name="Description" type="xs:string"/>
    <xs:attribute name="Required" type="xs:boolean"/>

    <xs:complexType name="ValidationAction">
        <xs:sequence>
            <xs:element name="api" type="xs:string" tns:Description="Indicates the validation API"/>
            <xs:element name="method" type="xs:string" tns:Description="Indicates the validation method"/>
            <xs:element name="beanName" type="xs:string" tns:Description="Validation bean name"/>
            <xs:element name="validationClass" type="xs:string" tns:Description="Validation class type"/>
            <xs:element name="idOwner" type="xs:int" tns:Description="Indicates the owner associated with the validation"/>
            <xs:element name="valid" type="xs:boolean" tns:Description="Indicates if validation is valid"/>
            <xs:element name="validator" type="tns:ApiValidator" minOccurs="0" maxOccurs="1"
                        tns:Description="Reference to the API validator"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="ApiValidator">
        <xs:annotation>
            <xs:appinfo>
                <jaxb:class ref="rd.ApiValidator"/>
            </xs:appinfo>
        </xs:annotation>
    </xs:complexType>


</xs:schema>

As suggested in : Jaxb implClass specification ignored for rootElement

Upvotes: 1

Views: 2404

Answers (1)

Santi
Santi

Reputation: 87

turned out, I had to change the line from:

  • xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="2.0" to
  • xmlns:jaxb="https://jakarta.ee/xml/ns/jaxb" jaxb:version="3.0"

Upvotes: 1

Related Questions