Reputation: 2432
I use jax-rs service. I have two fields in my class annotated with @XmlElement(required = true), one for Boolean, another for Integer. but if I send xml tags without value, for boolean I receive null, but for Integer I receive 0
@XmlElement(required = true)
private Integer intValue;
@XmlElement(required = true)
private Boolean booleanValue;
why I'm not receive null in Integer?
Upvotes: 1
Views: 3666
Reputation: 2432
I just should added defaultValue = "null"
@XmlElement(required = true, defaultValue = "null")
private Integer intValue;
There are 'interesting' (not expected) behavior of Integer fields. I can not find an explanation for what values are assigned to the default Integers in jaxb.
Upvotes: 1
Reputation: 149047
The required
property on the @XmlElement
annotation has no impact on the marshalling/unmarshalling performed by JAXB. It simply used during XML Schema generation to determine if the element declaration should have a minOccurs
of 0
(for false), or 1
(for true).
The difference between unmarshalling behaviour for Boolean
and Integer
is due to a bug in the JAXB reference implementation.
Upvotes: 1