Here is the XSD schema that i created for a WS
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="shipmentStatus" type="shipmentStatusType" />
<xs:complexType name="shipmentStatusType">
<xs:sequence>
<xs:element name="orderNumber" type="xs:int"/>
</xs:sequence>
<xs:attribute name="requestStatus">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="SHIPPED"/>
<xs:enumeration value="PENDING"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
When i generated Java classes using JAXB 2.1, it generated only one class i.e. shipmentStatusType. I was expecting that it will generate requestStatus as a JAVA Enum but it didn’t. Is it an expected behaviour or did i miss something?
Just extract your enum/simple type declaration to top-level one and use it as type of the XML attribute:
It will give you such an enum:
and class having it: