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 on Record property ignored for deserialization, if there is getter override #4626

Closed
1 task done
yihtserns opened this issue Jul 21, 2024 · 1 comment
Closed
1 task done
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

@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
@cowtowncoder
Copy link
Member

cowtowncoder commented Jul 21, 2024

Sidenote: created FasterXML/jackson-annotations#258 to allow @JsonIgnore on constructor parameters (regardless of what happens here), implemented.

@cowtowncoder cowtowncoder changed the title @JsonIgnore on Record property ignored for deserialization, if there is getter override @JsonIgnore on Record property ignored for deserialization, if there is getter override Jul 21, 2024
@cowtowncoder cowtowncoder changed the title @JsonIgnore on Record property ignored for deserialization, if there is getter override @JsonIgnore on Record property ignored for deserialization, if there is getter override Jul 21, 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