Search before asking
Describe the bug
@JsonIgnore on a Record component is ignored when the corresponding accessor method is overridden.
Version Information
Since 2.15.0.
Reproduction
record RecordWithJsonIgnore(int id, @JsonIgnore String name) {
@Override
public String name() {
return name;
}
}
RecordWithJsonIgnore deser = new ObjectMapper().readValue("{\"id\":123,\"name\":\"Bob\"}", RecordWithJsonIgnore.class);
// failed with:
// org.opentest4j.AssertionFailedError:
// Expected :RecordWithJsonIgnore[id=123, name=null]
// Actual :RecordWithJsonIgnore[id=123, name=Bob]
assertEquals(new RecordWithJsonIgnore(123, null), deser);
Expected behavior
No response
Additional context
There are typically 3 places to get an annotation info from:
| Where |
For this scenario |
| Constructor parameter |
Can't have @JsonIgnore info because @JsonIgnore's @Target does not include ElementType.PARAMETER UPDATE: Forgot to mention that the hardcoded prop.addCtor(..., false) in POJOPropertiesCollector also needs to be changed for this to work. |
| Accessor method |
When overridden, @JsonIgnore will not be "inherited" from original method |
| Field |
#3737 removed field info for deserialization, so it can't contribute the @JsonIgnore info |
Search before asking
Describe the bug
@JsonIgnoreon a Record component is ignored when the corresponding accessor method is overridden.Version Information
Since
2.15.0.Reproduction
Expected behavior
No response
Additional context
There are typically 3 places to get an annotation info from:
@JsonIgnoreinfo because@JsonIgnore's@Targetdoes not includeElementType.PARAMETERUPDATE: Forgot to mention that the hardcodedprop.addCtor(..., false)inPOJOPropertiesCollectoralso needs to be changed for this to work.@JsonIgnorewill not be "inherited" from original method@JsonIgnoreinfo