JAXB - How to customize simpleType of an element using external custom binding

94 Views Asked by At

I'm generating a set of pojos using xjc from a xsd schema and a xjb customization file. The schema define a complex type like this

   <xs:complexType name="PartyIdentification135">
        <xs:sequence>
            <xs:element maxOccurs="1" minOccurs="0" name="Nm" type="Max140Text"/>
            <xs:element maxOccurs="1" minOccurs="0" name="PstlAdr" type="PostalAddress24"/>
            <xs:element maxOccurs="1" minOccurs="0" name="Id" type="Party38Choice"/>
            <xs:element maxOccurs="1" minOccurs="0" name="CtryOfRes" type="CountryCode"/>
            <xs:element maxOccurs="1" minOccurs="0" name="CtctDtls" type="Contact4"/>
        </xs:sequence>
   </xs:complexType>

where Max140Text is a simpleType

<xs:simpleType name="Max140Text">
    <xs:restriction base="xs:string">
        <xs:minLength value="1"/>
        <xs:maxLength value="140"/>
    </xs:restriction>
</xs:simpleType>

Since the interbank network enforces a stricter restriction on the Nm tag length (Max 70) and since a Max70Text is already defined inside the xsd schema I would like to override the simpleType without altering the schema that is issued as ISO standard. I already have a customization of the PartyIdentification135 node like this

        <jaxb:bindings node="xsd:complexType[@name='PartyIdentification135']">
            <jaxb:class name="PartyIdentification"/>
            <jaxb:bindings node="xsd:sequence">
                <jaxb:bindings node="xsd:element[@name='Nm']">
                    <jaxb:property name="name"/>
                    <annox:annotate target="field">@com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty(namespace = "urn:iso:std:iso:20022:tech:xsd:pain.013.001.10")</annox:annotate>
                </jaxb:bindings>
            </jaxb:bindings>
        </jaxb:bindings>

But I couldn't figure out how to customize the Nm element definition forcing xjc to generate a Max70Text instead of a Max140Text

0

There are 0 best solutions below