MOXy BeanValidation gives me the ability to add validation to my JAXB classes.
Using MOXy\'s \"Bean Validation Plugin\" I can have Bean Validation in generated JAX
I think it is there. MOXy uses its own SchemaGen implementation for the process of generating XSD files from Java classes. SchemaGen was extended to automatically generate XSD Restrictions and Facets based on BV annotations found on Java classes. Since the schema generation process takes place upon creation of JAXBContext, the BV enhancement feature can be turned on/off by setting the following property (found in JAXBContextProperties) on JAXBContext:
/**
* Property for disabling/enabling generation of XML Facets during schemagen.
* The mapped value must be of type Boolean.
* If it's true, then facets will be generated, based on the BV annotations.
* If false, the BV annotations processing will be skipped during schemagen
* and no facets will be generated.
*
* @since 2.6
*/
public static final String GENERATE_FACETS = "eclipselink.generate.facets";
SchemaGen recognizes annotations provided by the BV API, including @Pattern.List. If SchemaGen encounters a field annotated with both @NotNull and @XmlElement(nillable = true), it will raise the BeanValidationException.notNullAndNillable().
Sample:
Map props = new HashMap( );
props.put("eclipselink.beanvalidation.facets", true);
JAXBContext jc = JAXBContext.newInstance(classes, properties);
SchemaOutputResolver sor = new MSOR();
jc.generateSchema(sor);