You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
I am not surprised it doesn't; contextual annotations probably are not applied to @JsonValue serialized values
So adding a failing test (under src/test/java/.../tofix) would make sense.
Fix is probably not trivial to do, although I could be wrong: contextualization should be done against accessor (Field, Getter) on which @JsonValue is applied. But there might not be BeanProperty created for it (as it's not really a property).
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: