I normally use objectMapper.setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL) because I never want the null values of my classes serialized. Except now I have a specific field should be written out, even if it is null. Is there a quick annotation I can put on this one field that overrides the Inclusion.NON_NULL property for that one field? What’s a good way to achieve this?
I normally use objectMapper.setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL) because I never want the null values of my classes
Share
With Jackson 1.x you can use
@JsonSerialize(include = Inclusion.ALWAYS)and with Jackson 2.x you can use@JsonInclude(Include.ALWAYS). These annotations will override the default config from yourObjectMapper.