Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure how JAXB unmarshalls boolean

I have some annotated JAXB beans which I am using to unmarshal some XML.

I have several attributes annotated with @XMLAttribute with the type Boolean.

@XmlAttribute private Boolean someAttribute;

I would like to customise the umarshalling of all boolean attribute so that only exactly the values "true" or "false" are allowed (e.g. "FALse" and not "wibble" would cause the unmarshalling to fail).

I would prefer to avoid having to set an @XmlJavaTypeAdapter on every Boolean attribute if possible. Is there any way to configure how JAXB unmarshals Boolean properties?

like image 721
lexicalscope Avatar asked Nov 05 '22 21:11

lexicalscope


1 Answers

You could create a Schema expressing your constraints and attach this to the Unmarshaller.

like image 193
Waldheinz Avatar answered Nov 12 '22 12:11

Waldheinz