Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAXB does not throw an Error on wrong dateTime values

Tags:

java

jaxb

I have an XML schema, where element Calling1 is defined like this:

<xsd:element name="Calling1" type="xsd:dateTime">

I have generated Jaxb bindings :

 <xjc extension="true" schema="${basedir}/message.xsd"
  destdir="${basedir}/src" package="org.test"/>

I am using JAXB to unmarshal XML documents to Java representation. If my XML cantains element Calling1, which value is not a correct dateTime, for example

<Calling1>NOT_A_DATETIME</Calling1>

JAXB does not throw any error, but returns me an java object, which property calling1 is null.

Why i get null, and not an Error? How can i change that Jaxb behaviour?

like image 264
never Avatar asked Oct 11 '22 04:10

never


1 Answers

Have you set the schema on your Unmarshaller by calling setSchema ? You will need to specify the xsd file as well as the Schema NS URI for validation to take place

like image 200
Bhaskar Avatar answered Oct 12 '22 21:10

Bhaskar