From what I have seen validation can be done againsta schema, but you must know the path to the schema in order to pass it into the set Schema() method.
Which is why it's stored in the XML file: ..Every example I see uses set Validating(true), which is now deprecated, so throws an exception.
This is the Java code I have so far, which seems to only do XML validation, not schema validation: OK, I've found the solution.
class governs the process of deserializing XML data into newly created Java content trees, optionally validating the XML data as it is unmarshalled.
It provides an overloading of unmarshal methods for many different input kinds.
These methods are useful for unmarshalling XML data where the root element corresponds to a local element declaration in the schema. If the unmarshal process is unable to unmarshal the root of XML content to a JAXB mapped object, a fatal error is reported that terminates processing by throwing JAXBException. The JAXBContext instance maintains a mapping of globally declared XML element and type definition names to JAXB mapped classes.
The unmarshal method checks if JAXBContext has a mapping from the root element's XML name and/or , if it exists, then the unmarshal operation will abort immediately by throwing a Unmarshal Exception .
You will have to create the Schema instances from the correspondingly available XSD, more info can be found here . We implemented a Validation Event Collector, and set this to handle validation events coming from the unmarshaller.
Rather than creating a general validating mechanism it might be better to have a general mechanism you inherit from for specific validating purposes i.e. Our Validation Event Collector throws an unchecked exception (JAXBParser Exception) which we then handle with Exception Mapper. Hi Andrew, Validating is indeed deprecated and you need to set the Schema object to validate against.
These unmarshal methods utilize JAXBContext 's mapping of global XML element declarations and type definitions to JAXB mapped classes to initiate the unmarshalling of the root element of XML data.
When the JAXBContext 's mappings are not sufficient to unmarshal the root element of XML data, the application can assist the unmarshalling process by using the unmarshal by declared Type methods.
Rather than creating a general validating mechanism it might be better to have a general mechanism you inherit from for specific validating purposes i.e. Trying to follow his instructions, I have implemented a Context Resolver as follows: @Provider public class Validating JAXBContext Resolver implements Context Resolver and a JAXBContext (modeled after the JSONJAXBContext in the jersey source) as: public class Validating JAXBContext extends JAXBContext Now, when I hit a method that would require unmarshalling content from XML, I receive an exception at my call to set Validating: