Skip to content

@JsonIgnore on Record property ignored for deserialization, if there is getter override #4626

@yihtserns

Description

@yihtserns

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    2.18Issues planned at 2.18 or laterRecordIssue related to JDK17 java.lang.Record support

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions