Migrating to Java8 and JAXB 2 adds @XmlSchemaType(name = "anySimpleType") annotation for referred types
I started facing one strange issue, once my project got upgraded to Java 8 and JAXB 2. I had list of enums, doubles as part of my XSD. I used to define them in following manner.
<xs:complexType name="TOCForResultCType">
<xs:sequence>
<xs:element name="SupportedPPType" minOccurs="0" type="PPType">
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:simpleType name="PPType">
<xs:list itemType="PostProcessingTypeSType"/>
</xs:simpleType>
<xs:simpleType name="PostProcessingTypeSType">
<xs:restriction base="xs:string">
<xs:enumeration value="ANIMATION"/>
<xs:enumeration value="NONE"/>
</xs:restriction>
</xs:simpleType>
After migration to java8 and jaxb 2, it generated code like this
public class TOCForResultCType {
@XmlList
@XmlElement(name = "SupportedPPType")
@XmlSchemaType(name = "anySimpleType")
protected List<PostProcessingTypeSType> supportedPPType;
Here one can see this extra annotation @XmlSchemaType(name = "anySimpleType"). This extra annotation creates ClassCastException when trying to marshall the content using JAXB Marshaller.
This issue was happening when we were creating list of object using simpleType annotation. I also faced this issue when trying to create List in the same fashion.