0

I have the following schema which I would like to create an enum class

<xs:simpleType name="TopicValuesType">
    <xs:union memberTypes="xs:string">
        <xs:simpleType>
            <xs:restriction base="xs:string">
                <xs:enumeration value="APPLE"/>
                <xs:enumeration value="BANANA"/>
                <xs:enumeration value="ORANGE"/>
                <xs:enumeration value="#"/>
            </xs:restriction>
        </xs:simpleType>
    </xs:union>
</xs:simpleType>
<xs:complexType name="TopicType">
    <xs:attribute name="name" type="TopicValuesType" use="required"/>
</xs:complexType>

I've tried to create a binding class but it doesn't work.

<bindings schemaLocation="MySchema.xsd">
        <globalBindings typesafeEnumBase="xs:string" typesafeEnumMemberName="generateName" />
 </bindings>

I've read this post XJC does not generate enum inside xs:union where it's not possible to create enum.

Is there any other way to create enum out of this schema? Unfortunately I'm unable to edit the schema because it's from a third party.

I'm using maven jaxb2

 <groupId>org.jvnet.jaxb2.maven2</groupId>
 <artifactId>maven-jaxb2-plugin</artifactId>
 <version>0.14.0</version>
user293655
  • 508
  • 1
  • 6
  • 23
  • The union part in the xsd is preventing the enum generation. but why is the union there? With this union in place the xml validator does no longer check the content of the name attribute against the defined restriction options. So regardless of the content of the name attribute the xml message is valid. Removing the union does not change the layout of the xml message, an enum class will be generated using jaxb and the validator will look at the restrictions. – martijn Oct 20 '20 at 06:02
  • Unfortunately I can’t change the schema. Why it is there I don’t know either. It’s from 3rd party. Is there anyway to use enum? Or am I stuck with string? – user293655 Oct 20 '20 at 06:05

0 Answers0