本文介绍了对于Integer,XmlElement required = true不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用jax-rs服务。我的类中有两个用@XmlElement注释的字段(required = true),一个用于布尔值,另一个用于Integer。但是如果我发送没有值的xml标签,对于布尔我收到空,但对于整数我收到0
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?
推荐答案我应该添加defaultValue =null
I just should added defaultValue = "null"
@XmlElement(required = true, defaultValue = "null") private Integer intValue;整数字段有'有趣'(不是预期的)行为。我找不到在jaxb中为默认整数赋值的解释。
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.
更多推荐
对于Integer,XmlElement required = true不起作用
发布评论