How to get error details from JAXB Validator?

Gamedevelop

New Member
I have some classes with JAXB annotations, I have created some instances and I need to validate them against my XSD files. I should be able to get the details of what is wrong when the objects are invalid.So far I haven't had luck, I know about this class ValidationEventHandler but apperantly I can use it with the Unmarshaller class, the problem is that I have to validate the objects not the raw XML.I have this code:\[code\]MyClass myObject = new MyClass();JAXBContext jaxbContext = JAXBContext.newInstance("x.y.z");JAXBSource jaxbSource = new JAXBSource(jaxbContext, myObject);SchemaFactory factory = SchemaFactory .newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);Source schemaFile = new StreamSource(getClass().getClassLoader() .getResourceAsStream("mySchema.xsd"));Schema schema = factory.newSchema(schemaFile);Validator validator = schema.newValidator();validator.validate(jaxbSource);\[/code\]This code will work, it will validate the object and throw an exception with the message, something like this:\[quote\] cvc-pattern-valid: Value '12345678901' is not facet-valid with respect to pattern '\d{10}' for type 'id'.]\[/quote\]The problem is that I need specific details, with a string like that I would have to parse all the messages.
 
Back
Top