We are using JAXB to handle our wsdl validation. In the wsdl we have an enumeration like so:
<xs:simpleType name="myEnum">
<xs:annotation>
<xs:documentation>The enums which matter.</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:enumeration value="MYENUM_1">
<xs:annotation>
<xs:documentation>MYENUM_1 is the first enum.</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="MYENUM_2">
<xs:annotation>
<xs:documentation>MYENUM_2 is the second enum.</xs:documentation>
</xs:annotation>
</xs:enumeration>
</xs:restriction>
</xs:simpleType>
If we pass in an invalid string as an enum for example, MYENUM_7, the value is set to null, instead of throwing an error like we would expect. Digging into the code, we find the following from RuntimeEnumLeafInfoImpl.java:
package com.sun.xml.bind.v2.model.impl;
//...
public T parse(CharSequence lexical) throws AccessorException, SAXException {
// TODO: error handling
B b = baseXducer.parse(lexical);
if(b==null) {
return null;
}
return parseMap.get(b);
}
It is clear to see that the parseMap is our list of enums, but if the key to the map, in this case the value of b, is not in the map it just returns null. We would like it to throw and exception of some sort if b is not in parseMap.
Short of fixing this and recompiling our own JAXB is there some other way to solve this?
EDIT: for clarification
We are using JAXB 2.1.9, and we want to unmarshall the data AND validate it. It is certainly possible I have overlooked something in the documentation about validation.