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
@JsonIgnore & @JsonProperty.access=READ_ONLY on Record property ignored for deserialization, if @JsonProperty.value is the same as the property name
#4628
Open
1 task done
yihtserns opened this issue
Jul 21, 2024
· 0 comments
I searched in the issues and found nothing similar.
Describe the bug
When a @JsonProperty.value is given the same value as the property it is annotated on, @JsonProperty.access=READ_ONLY seems to be ignored during deserialization.
Version Information
Oldest I tested this with is 2.14.2, latest is 2.18.
Reproduction
For @JsonIgnore
recordRecordWithJsonIgnoreNamedProperty(intid,
// Note that @JsonProperty.value == "xxx", which has the same name as the Record component `xxx`@JsonIgnore@JsonProperty(value = "xxx") Stringxxx) {
}
RecordWithJsonIgnoreNamedPropertydeser = newObjectMapper().readValue("{\"id\":123,\"xxx\":\"Bob\"}", RecordWithJsonIgnoreNamedProperty.class);
// failed with:// org.opentest4j.AssertionFailedError:// Expected :RecordWithJsonIgnoreNamedProperty[id=123, xxx=null]// Actual :RecordWithJsonIgnoreNamedProperty[id=123, xxx=Bob]assertEquals(newRecordWithJsonIgnoreNamedProperty(123, null), deser);
For @JsonProperty.access=READ_ONLY
recordRecordWithReadOnlyNamedProperty(intid,
// Note that @JsonProperty.value == "xxx", which has the same name as the Record component `xxx` @JsonProperty(value = "xxx", access = JsonProperty.Access.READ_ONLY) Stringxxx) {
}
RecordWithReadOnlyNamedPropertydeser = newObjectMapper().readValue("{\"id\":123,\"xxx\":\"Bob\"}", RecordWithReadOnlyNamedProperty.class);
// failed with:// org.opentest4j.AssertionFailedError: // Expected :RecordWithReadOnlyNamedProperty[id=123, xxx=null]// Actual :RecordWithReadOnlyNamedProperty[id=123, xxx=Bob]assertEquals(newRecordWithReadOnlyNamedProperty(123, null), deser);
Expected behavior
No response
Additional context
NOTE: Seems to be an edge case that user wouldn't/shouldn't encounter. Not reproducible for non-Record classes. I'm not personally affected by this, just something I found when working on #4624:
yihtserns
changed the title
@JsonProperty.access=READ_ONLY on Record property ignored for deserialization, if @JsonProperty.value is the same as the property name
@JsonIgnore & @JsonProperty.access=READ_ONLY on Record property ignored for deserialization, if @JsonProperty.value is the same as the property name
Jul 22, 2024
Search before asking
Describe the bug
When a
@JsonProperty.value
is given the same value as the property it is annotated on,@JsonProperty.access=READ_ONLY
seems to be ignored during deserialization.Version Information
Oldest I tested this with is
2.14.2
, latest is2.18
.Reproduction
For
@JsonIgnore
For
@JsonProperty.access=READ_ONLY
Expected behavior
No response
Additional context
NOTE: Seems to be an edge case that user wouldn't/shouldn't encounter. Not reproducible for non-Record classes. I'm not personally affected by this, just something I found when working on #4624:
@JsonIgnore
: https://github.com/yihtserns/jackson-databind/blob/8c14e0916647128082cd8739d7e87e3884c1aa5e/src/test-jdk17/java/com/fasterxml/jackson/databind/records/RecordWithJsonIgnoreTest.java#L64-L68@JsonProperty.access=READ_ONLY
: https://github.com/yihtserns/jackson-databind/blob/8c14e0916647128082cd8739d7e87e3884c1aa5e/src/test-jdk17/java/com/fasterxml/jackson/databind/records/RecordWithReadOnlyTest.java#L85-L93The text was updated successfully, but these errors were encountered: