chad
chad

Reputation: 7529

How can I define validation rules for JAXB if not using XSD's?

So, we have a project that uses jaxb to marshal and unmarshal. We on't have XSD's. We only have annotated Java objects. So, when the xml comes into our system, we unmarshal it. The JAXB docs talk about validating the java objects during the unmarshalling phase. I would like to be able to add some validation rules somewhere ( annotations on the java source, next to the jaxb annotations, perhpas? ) that would give me a readable, maintainable, declarative style validation mechanism. But I'm not sure that JAXB supports this; perhaps the JAXB validation is only driven by XSD's. Suggestions?

http://docs.oracle.com/cd/E17802_01/webservices/webservices/docs/1.5/tutorial/doc/JAXBWorks2.html#wp82802

Upvotes: 1

Views: 294

Answers (1)

bdoughan
bdoughan

Reputation: 149017

JAXB Validation (JSR-222)

JAXB validation is based on an XML schema (see: http://blog.bdoughan.com/2010/12/jaxb-and-marshalunmarshal-schema.html).

Bean Validation (JSR-303 & 349)

You could use Bean Validation 1.0 (JSR-303) or 1.1 (JSR-349) annotations on your model to define validation rules.

Upvotes: 1

Related Questions