对于Integer,XmlElement required = true不起作用 [英] XmlElement required = true for Integer doesn't work

查看:410
本文介绍了对于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不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆