[英]XmlElement required = true for Integer doesn't work
I use jax-rs service. 我使用jax-rs服务。 I have two fields in my class annotated with @XmlElement(required = true), one for Boolean, another for Integer.
我的类中有两个用@XmlElement(required = true)注释的字段,一个用于布尔值,另一个用于Integer。 but if I send xml tags without value, for boolean I receive null, but for Integer I receive 0
但是,如果我发送没有值的xml标记,则对于布尔值,我会收到null,但是对于整数,我会收到0
@XmlElement(required = true)
private Integer intValue;
@XmlElement(required = true)
private Boolean booleanValue;
why I'm not receive null in Integer? 为什么我在Integer中没有收到null?
I just should added defaultValue = "null" 我只应该添加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.
我找不到有关在jaxb中将哪些值分配给默认Integer的解释。
The required
property on the @XmlElement
annotation has no impact on the marshalling/unmarshalling performed by JAXB. @XmlElement
批注上的required
属性对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). 它仅在XML Schema生成期间用于确定元素声明的
minOccurs
为0
(对于false)或1
(对于true)。
The difference between unmarshalling behaviour for Boolean
and Integer
is due to a bug in the JAXB reference implementation. Boolean
和Integer
解组行为之间的差异是由于JAXB参考实现中的错误所致。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.