Question

If XML is generated by JAXB classes(not by XSD), I don't have an XSD to validate. How do I validate the XML? Does the JAXB does validation of XML automatically before it starts unmarshalling?

Was it helpful?

Solution

If you don't have XSD, JAXB will still perform "structual" validation. For example if you have annotated JAXB class property with "required" or specified specific "accessorder" and the input XML doesn't confirm to the annotation's values you will get exception. However you won't be able to perform "data" validation like specific XML element is restricted to have "8" character length (I believe JEE7 will integrate BeanValidation and wish JAXB leverages this spec).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top