【发布时间】:2015-07-09 09:17:29
【问题描述】:
我正在使用 jersey 序列化 Web 服务中的响应。 我不希望服务返回空值,所以我使用相应的注释,如下所示:
@JsonInclude(Include.NON_NULL)
class City{
String name;
Stat stats;
}
Stat 类看起来像这样:
class Stat{
int population;
int femalePopulation;
int malePopulation;
}
如果 Stat 的属性为空,我不希望显示它们。但出于某种原因,我不断得到那些。我试过在Stat 类中使用@JsonInclude(Include.NON_NULL),但它不起作用:(
任何帮助将不胜感激。
编辑:
抱歉,我的例子不是最好的。我知道原语类型有默认值。我已经尝试在 Stat 类中添加注释,但它对我来说不起作用:/
class Stat{
Integer population;
Integer femalePopulation;
Integer malePopulation;
}
【问题讨论】: