Open sikorskii opened 2 days ago
Please try later versions of Jackson, like recently released 2.18 and please let us know!
I have a feeling nested deserialization of Map<String, Object>
might not work.... 🤔
@JooHyukKim I tried version 2.18.0 and behavior did not change
I have a feeling nested deserialization of Map<String, Object> might not work.... 🤔
Okay, probably this is the cause. Will try to look into it later! Thank you for reporting and providing reproduction tho
From quick look:
@JsonValue
serialized valuesSo 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:
I want to write to a JSON object of the type Map<String, Object>, where the values are similar maps.
I want to have behavior similar to
In other words, I should not write keys with null values, even in nested maps. BUT
I do not have access to the objectMapper instance, so the problem must be solved "externally."
And there are options for wrapper classes that can have annotations attached to them:
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