简体   繁体   中英

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 (eg "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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM