我正在使用Fasterxml Jackson 2.2.2。
我有一个简单的POJO,其中包含一个布尔(原始数据类型)属性。当默认的BeanSerializer
和BeanPropertyWritter
尝试将其序列化时,当该属性的值为false
时,它将被跳过。
我想要:
{"id":1, "enabled":false}
我所得到的是:
{"id":1}
< p > < code > BeanPropertyWritter 中的代码如下:
// and then see if we must suppress certain values (default, empty)
if (_suppressableValue != null) {
if (MARKER_FOR_EMPTY == _suppressableValue) {
if (ser.isEmpty(value)) {
return;
}
} else if (_suppressableValue.equals(value)) {
return;
}
}
我已经进行了调试并发现
BeanPropertyWritter._suppressableValue
等于Boolean(false)
,所以当一个false布尔值到达此块时,它只会返回并且没有输出被返回。我的选择是什么?我能否配置属性的写入器来取消其
_suppressableValue
?哪种方法最简单和更简单?
JsonSerialize.Inclusion.NON_DEFAULT
吗? - HiJon89