-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Labels
2.18Issues planned at 2.18 or laterIssues planned at 2.18 or laterRecordIssue related to JDK17 java.lang.Record supportIssue related to JDK17 java.lang.Record support
Milestone
Description
Search before asking
- I searched in the issues and found nothing similar.
Describe the bug
A Record component whose accessor method is overridden and:
- Not included in @JsonIncludeProperties, or
- Included in @JsonIgnoreProperties
...will still get serialized into the generated JSON.
Version Information
Since 2.15.0.
Reproduction
For @JsonIncludeProperties
record Id2Name(int id, String name) {
}
record RecordWithJsonIncludeProperties(@JsonIncludeProperties("id") Id2Name child) {
@Override
public Id2Name child() {
return child;
}
}
String json = new ObjectMapper().writeValueAsString(new RecordWithJsonIncludeProperties(new Id2Name(123, "Bob")));
// failed with:
// org.opentest4j.AssertionFailedError:
// Expected :{"child":{"id":123}}
// Actual :{"child":{"id":123,"name":"Bob"}}
assertEquals("{\"child\":{\"id\":123}}", json);For @JsonIgnoreProperties
record Id2Name(int id, String name) {
}
record RecordWithJsonIgnoreProperties(@JsonIgnoreProperties("name") Id2Name child) {
@Override
public Id2Name child() {
return child;
}
}
String json = new ObjectMapper().writeValueAsString(new RecordWithJsonIgnoreProperties(new Id2Name(123, "Bob")));
// failed with:
// org.opentest4j.AssertionFailedError:
// Expected :{"child":{"id":123}}
// Actual :{"child":{"id":123,"name":"Bob"}}
assertEquals("{\"child\":{\"id\":123}}", json);Expected behavior
No response
Additional context
NOTE: I'm not personally affected by this, just something I found when testing for #4626.
Metadata
Metadata
Assignees
Labels
2.18Issues planned at 2.18 or laterIssues planned at 2.18 or laterRecordIssue related to JDK17 java.lang.Record supportIssue related to JDK17 java.lang.Record support