Validate javax bind annotations, not schema

The latest Sun JAXB implementation is used, but can rely on XJC to generate the right annotations. A few examples in which the XJC does not bind XMLElement or XMLAttribute annotations for no logical reason. Plus there are problems with the logic of the plugin platform. In any case, I want to abandon the idea of ​​writing diagrams just to create a POJO, and then loading the diagrams just for verification.

Does anyone have a way to test directly against Javax binding annotations? Saw a cool workaround: how can I figure out jaxb and use schema validation without using an explicit schema file

If the circuit was dynamically created just for verification. Looking for an approach that goes directly against annotations (like Hibernate Validator and JSR 303, but specifically for Javax binding annotations)?

+4
source share
1 answer

There is no standard check that can be performed on JAXB annotations. In truth, for the most part, this is because the typed nature of the object model reduces the amount of invalid input that may appear (for example, if my client element has a child address element, then my Customer object has the Address property, t set that or, except for the Address object, to this property).

If you want the check to be related to restricting the collection to certain numerical elements (since you have maxOccurs = "10") or a string with a certain length (since you have a circuit facet). JAXB 2.X (JSR 222) does not by default generate them in your object model (although you can certainly add them yourself, as people do when using JPA), using JSR 303 and starting the validator.

Other questions related to your question:

  • If you are having problems with the XJC tool, please consider entering an error into it:

  • If annotations are missing, @XmlElement is used by default, so some of these annotations may be missing for this reason. Annotation is usually added only for a name or namespace.

  • With JAXB (like JPA) you can start with POJO. JAXB annotations can be added to customize the XML presentation.

+1
source

All Articles