JaxB when binding an improper date format to XMLGregorianCalendar is not throwing exception. Instead it assigns null. What could be the problem?
@XmlAttribute(name = "travelEndDate", required = true)
@XmlSchemaType(name = "date")
protected XMLGregorianCalendar travelEndDate;
<xs:complexType name="SearchCriteria">
<xs:attribute name="travelStartDate" type="xs:date" use="required"/>
<xs:attribute name="travelEndDate" type="xs:date" use="required"/>
</xs:complexType>
Note: I’m the EclipseLink JAXB (MOXy) lead, and a member of the JAXB 2.X (JSR-222) expert group.
This behaviour will vary a little between JAXB implementations. MOXy for example will throw the following exception if the value is incorrect:
Workaround
To get an error reported on any JAXB implementation you can set an XML schema on the unmarshaller to perform validation:
Or you can implement an
XmlAdapterto control the conversion (and throw an exception if necessary) yourself: