@JsonValue ignores annotations on annotated field (particularly @JsonInclude) #4762
Open
1 task done
Labels
2.18
Issues planned at 2.18 or later
Search before asking
Describe the bug
The problem is as follows:
In other words, I should not write keys with null values, even in nested maps. BUT
But when placing @JsonInclude(...NON_NULL) above the NonNullWrapper class, nulls are removed only at the top level. Jackson then sees regular maps in the values, which naturally don’t have annotations, and applies the default policy.
Similarly, Jackson ignores such annotations on a field marked with @JsonValue.
Inside Jackson's source code, during serialization (with @JsonValue), the JsonValueSerializer simply does not have information about the annotations that are attached to the marked field.
In the end, the question is: Is this behavior expected? Can this task be solved using annotations or other ways? However, I would prefer not to write my own JsonSerializer, Filter, or similar things for this.
Version Information
2.15.3 (but still fails on 2.18.0)
Reproduction
Results
NonNullWrapper
AnotherNonNullWrapper
Expected behavior
@JsonInclude annotation has effect on nested maps or/and @JsonValue marked field
Additional context
No response
The text was updated successfully, but these errors were encountered: