Reputation: 4086
I have annotated a POJO with @JsonInclude(JsonInclude.Include.NON_NULL)
to exclude all null fields while serialization/deserialization.
But now I need to exclude one of the fields from this behaviour. ie - I want to send over the value of a field as null if it has a null value.
There is some update in legacy code which has put me in this situation.
How can i achieve this?
Edit:
Would using a JSONSerialize(include=CustomSerializer.class) give higher precedence to the CustomSerializer?
Upvotes: 0
Views: 5072
Reputation: 315
Use @JsonInclude(Include.ALWAYS)
annotation on your field. This will override @JsonInclude(Include.NON_NULL)
on the class level.
Upvotes: 3