I'm using Fasterxml Jackson 2.2.2
I have a simple pojo with a boolean (primitive) attribute. When the default BeanSerializer and BeanPropertyWritter try to serialize it, this attribute is skipped when its value is false.
I want:
{"id":1, "enabled":false}
What I get is:
{"id":1}
The code in BeanPropertyWritter is:
// 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;
}
}
I've debugged it and found that BeanPropertyWritter._suppressableValue equals Boolean(false), so when a false boolean arrives to this block, it just returns and no output is returned.
What are my options? Can I configure the attribute's writter to un-set its _suppressableValue? What would be the easiest and simpler solution?
As was suggested, your
ObjectMappersettings are probably non-default, and specify inclusion strategy ofNON_DEFAULT.But you can add
@JsonIncludeto override this either on your POJO class, or even for boolean property itself: make sure to useInclusion.ALWAYS.