Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@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
Labels
2.18 Record Issue related to JDK17 java.lang.Record support

Comments

@yihtserns
Copy link
Contributor

yihtserns commented Jul 21, 2024

Search before asking

  • 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

record RecordWithJsonIgnoreNamedProperty(int id,
                                         // Note that @JsonProperty.value == "xxx", which has the same name as the Record component `xxx`
                                         @JsonIgnore @JsonProperty(value = "xxx") String xxx) {
}

RecordWithJsonIgnoreNamedProperty deser = new ObjectMapper().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(new RecordWithJsonIgnoreNamedProperty(123, null), deser);

For @JsonProperty.access=READ_ONLY

record RecordWithReadOnlyNamedProperty(int id,
                                       // Note that @JsonProperty.value == "xxx", which has the same name as the Record component `xxx` 
                                       @JsonProperty(value = "xxx", access = JsonProperty.Access.READ_ONLY) String xxx) {
}

RecordWithReadOnlyNamedProperty deser = new ObjectMapper().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(new RecordWithReadOnlyNamedProperty(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 yihtserns added the to-evaluate Issue that has been received but not yet evaluated label Jul 21, 2024
@cowtowncoder cowtowncoder added Record Issue related to JDK17 java.lang.Record support 2.18 and removed to-evaluate Issue that has been received but not yet evaluated labels Jul 21, 2024
@yihtserns 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.18 Record Issue related to JDK17 java.lang.Record support
Projects
None yet
Development

No branches or pull requests

2 participants