4

I tried a couple of things:

1)

<xs:simpleType name="matchAnalysisType">
    <xs:restriction base="xs:string">
        <xs:enumeration value="A"/>
        <xs:enumeration value=""/>
    </xs:restriction>
 </xs:simpleType>

JaxB DOESN'T generate enums and instead marks matchAnalysisType as string for the corresponding element type.

2) Use 'nillable':

 <xs:element name="matchAnalysisType" type="matchAnalysisType"  
     nillable="true">                
 </xs:element>

JaxB throws error that '' is not valid.

The issue holds true for other element types like the following:

 <xs:element name="accountNumber" minOccurs="0">                
     <xs:simpleType>
         <xs:restriction base="xs:integer">
             <xs:totalDigits value="9"/>
         </xs:restriction>
     </xs:simpleType>
  </xs:element>

I'd like to have a sample xml that allows this the following without any validation errors.

 <accountNumber></accountNumber> 

Thoughts?

2 Answers 2

2

JAXB does not have a default enum value name for enum values corresponding to "". Your JAXB implementation can generate a Java enum corresponding to this XML schema type if you use an external bindings file to provide a name.

binding.xml

<jxb:bindings
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
    version="2.1">
    <jxb:bindings schemaLocation="your-schema.xsd">
        <jxb:bindings node="//xs:simpleType[@name='matchAnalysisType']/xs:restriction/xs:enumeration[@value='']">
            <jxb:typesafeEnumMember name="BLANK"/>
        </jxb:bindings>
    </jxb:bindings>
</jxb:bindings>

XJC Call

The binding file is specified in the XJC call using the -b parameter:

xjc -b binding.xml your-schema.xsd

For More Information

Sign up to request clarification or add additional context in comments.

1 Comment

pleas seemmy response above. FYI, not sure how you can add a large 'comment' to an answer.
1

Here is the solution :

tyesafeEnumMemberName has by default value generateError and you can specify value generateName.

This attribute was not present in our xjc file. Now this fixes the autogneration.

<jxb:bindings schemaLocation="your.xsd" node="/xsd:schema"> 
                <jxb:globalBindings typesafeEnumMaxMembers="9000"         typesafeEnumMemberName="generateName" >
                            <xjc:simple/>
            </jxb:globalBindings>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.