JAXB: Can I make XmlAttribute's parameter “required=true” to default?
-
22-07-2019 - |
Question
I have
@XmlAttribute(required=true)
in hundreds places in a projects.
Can I make this default?...
...So that I then only need to specify
@XmlAttribute(required=false)
when needed.
Solution
No, that behaviour is hard-wired. However, the required
attribute is really a lightweight alternative to a proper XML schema. If you need better control over document validation, then I suggest you define an XML Schema for your documents, and inject the schema into the JAXBContext
. The documents will then be checked on marshalling and unmarshalling, and you won't have to rely on the annotations for validation.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow