对于Integer,XmlElement required = true不起作用

编程入门 行业动态 更新时间:2024-10-12 22:29:41
本文介绍了对于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不起作用

本文发布于:2023-11-23 01:14:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1619580.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不起作用   XmlElement   Integer   true   required

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!