How could I have different behaviors for null serialization of different JavaType? #266
-
Given an entity, it has two attributes, and the values of both are null. private String name;
private Integer age; I hope to serialize integers with a value of null as 0 and strings with a value of null as empty strings. So the expected result is {"name":"","age":0} I tried to use a customized serializer to handle this situation. But I found that when the framework detects that the value is null, it will use the default null serializer. During the troubleshooting process, it was found that this can be achieved by adding the I'm wondering if there are any other solutions? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
One possibility is using
and if you do not want to use annotations (even mix-in annotations), can override method |
Beta Was this translation helpful? Give feedback.
One possibility is using
@JsonSerialize.nullsUsing
:and if you do not want to use annotations (even mix-in annotations), can override method
findNullSerializer()
inAnnotationIntrospector
(default one beingJacksonAnnotationIntrospector
).