Search code examples
javaxsdcode-generationjibx

JiBX generates binding that ignores attribute namespace


I have the following schema (fragment):

<xs:complexType name="partnerPaymentsItemType">
    <xs:sequence>
        <xs:element name="changeTime" type="dateTime"/>
        <xs:element name="statusId" type="shortId"/>
        <xs:element name="paymentPointId" type="shortString"/>
        <xs:element name="money" type="currency"/>
        <xs:element name="paymentDestination" type="shortString"/>
        <xs:element name="paymentDestinationType" type="shortId"/>
        <xs:element name="subagentId" type="shortId" minOccurs="0"/>
        <xs:element name="discountCardNumber" type="xs:string" minOccurs="0"/>
        <xs:element name="amountAll" type="currency" minOccurs="0"/>
        <xs:element name="rewardPercent" type="percentAmount" minOccurs="0"/>
        <xs:element name="rewardPercentValue" type="percentAmount" minOccurs="0"/>
    </xs:sequence>
    <xs:attribute name="paymentTime" use="required" type="dateTime"/>
    <xs:attribute name="externalId" use="required" type="id"/>
    <xs:attribute name="registeredId" use="required" type="id"/>
</xs:complexType>

I use JibX Codegen tool to generate sources from it, and then to compile binding that should allow me to unmarshal XML to Java objects. Here is my codegen settings:

<schema-set xmlns:xs="http://www.w3.org/2001/XMLSchema"
        delete-annotations="true"
        prefer-inline="false"
        generate-all="true"
        show-schema="true"
        type-substitutions="xs:date xs:string"
        package="here.lays.my.package">
    <class-decorator     class="org.jibx.schema.codegen.extend.SerializableDecorator"/>
</schema-set>

Later, I try to parse an XML document which has namespace prefixes for both tags and attributes, which results an exception saying

Missing required attribute "paymentTime"

Debugging through JiBX sources shown that it tries to look for attribute with no namespace and name "paymentTime" in a document, while a document has an attribute with a namespace mapped to URL, and not able to find it of course.

I have decompiled binding with JAD and it searches for attribute with null namespace:

public static PartnerPaymentsItemType JiBX_beeline_binding_unmarshalAttr_1_93(PartnerPaymentsItemType arg1, UnmarshallingContext arg2)
    throws JiBXException
{
    arg2.pushTrackedObject(arg1);
    arg1;
    arg1.setPaymentTime(arg2.attributeText(null, "paymentTime"));
    arg1.setExternalId(Utility.parseLong(WhitespaceConversions.trim(arg2.attributeText(null, "externalId"))));
    arg1.setRegisteredId(Utility.parseLong(WhitespaceConversions.trim(arg2.attributeText(null, "registeredId"))));
    arg2.popObject();
    return arg1;
}

I would be grateful for any advise that could help resolving the issue - like, why JiBX generated such mapping, how to make it respect attribute namespace, and so on.


Solution

  • JiBX behavior was actually correct, namespace prefixes for attributes were not intended based on xsd.

    Actual solution was to replace JiBX with XJC/JAXB and separate schema for the entity where I needed namespace prefixes for attributes.