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

@JsonIncludeProperties, @JsonIgnoreProperties ignored when serializing Records, if there is getter override #4630

Closed
1 task done
yihtserns opened this issue Jul 21, 2024 · 1 comment
Labels
2.18 Record Issue related to JDK17 java.lang.Record support
Milestone

Comments

@yihtserns
Copy link
Contributor

Search before asking

  • I searched in the issues and found nothing similar.

Describe the bug

A Record component whose accessor method is overridden and:

...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.

@yihtserns
Copy link
Contributor Author

Apparently #4627 will also fix this.

@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
@cowtowncoder cowtowncoder changed the title @JsonIncludeProperties & @JsonIgnoreProperties is ignored when serializing Records, if there is getter override @JsonIncludeProperties, @JsonIgnoreProperties ignored when serializing Records, if there is getter override Jul 21, 2024
@cowtowncoder cowtowncoder changed the title @JsonIncludeProperties, @JsonIgnoreProperties ignored when serializing Records, if there is getter override @JsonIncludeProperties, @JsonIgnoreProperties ignored when serializing Records, if there is getter override Jul 21, 2024
cowtowncoder added a commit that referenced this issue Jul 23, 2024
@cowtowncoder cowtowncoder added this to the 2.18.0 milestone Jul 25, 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