0

How to enable validation against schema with Jaxb2Marshaller? Wiht example below If DateTime tag is wrong(should be with T "2015-09-09T16:56:39"), I don't get exception, the unmarshaller just return model with null.

        schema: <xs:element name="ExecutionTime" minOccurs="0" maxOccurs="1"
                type="xs:dateTime" />

        tag example   <ExecutionTime>2015-09-09 16:56:39</ExecutionTime>



            Jaxb2Marshaller marshaller = null;
            marshaller = new Jaxb2Marshaller();
            marshaller.setContextPath(contextPath);
            ClassPathResource schemaResource = new   ClassPathResource(classpathXSD);
            marshaller.setSchema(schemaResource);
            marshaller.setMappedClass(Entity.class);

            marshaller.unmarshal(stringSource)
magulla
  • 499
  • 1
  • 9
  • 22
  • Have you seen [this link](http://stackoverflow.com/a/26176086/3364187) ? I think is helpful – Xstian Oct 23 '15 at 08:51
  • yes, but I doesn't have answer. Only says again that specifing schema doesn't make Srping Jaxb2Marshaller to validate the xml against schema. – magulla Oct 23 '15 at 20:26

1 Answers1

0
..
marshaller.setValidationEventHandler(validationEvent -> processEvent(validationEvent));
..

So what I found, is if you specify this, you'll actually start getting validation error events and exceptions, if your XML has invalid data with regards to XSD.

magulla
  • 499
  • 1
  • 9
  • 22