Search code examples
javaxmljaxbjax-rsrequired

XmlElement required = true for Integer doesn't work


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?


Solution

  • 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.