Validating mutually exclusive properties (like xs:choice) in Jackson for XML #775
Replies: 2 comments 2 replies
-
I don't think that any of the Jackson volunteers has much time to spend on features like this. If you want to try building it yourself, we can review it. |
Beta Was this translation helpful? Give feedback.
-
Quick answer: no, Jackson does not have support for validation across properties -- 2 areas Jackson explicitly defines as sort of off-limits (or, maybe, limited support area):
For (2) the idea is to instead of use separate validation library like Bean Validation API. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
In XML schemas, there is a "choice" type. This type indicates that one and only one of the specified values should be provided in the XML. It is similar to the UNION type in C/C++.
Since Java does not have support for a UNION type, classes are usually created with all possible properties.
For example, I have the XSD file below:
For this, the generated Java class is as follows:
It may cause inconsistencies in generated XML file, as the "cpf" and "cnpj" fields should never be filled in simultaneously.
Is it possible to perform this validation in Jackson?
I think an annotation like the one below would be interesting:
And Jackson would prevent two or more properties with the same annotation from being filled at the time of serialization. This would guarantee the integrity of the generated XML with the schema.
Beta Was this translation helpful? Give feedback.
All reactions