Skip to content

@JsonProperty.value + @JsonIgnore on setter does not work anymore since 2.18.4 #5398

Description

@victor-noel-pfx

Search before asking

  • I searched in the issues and found nothing similar.

Describe the bug

Hi,

The following fails since 2.18.4 (I tested also 2.20.1):

    class Test {
        private String prop = "someValue";

        @JsonProperty(value = "renamedProp")
        public String getProp() {
            return prop;
        }

        @JsonIgnore
        public void setProp(String prop) {
            this.prop = prop;
        }

        public static void main(String[] args) throws Exception {
            var m = new ObjectMapper();
            m.readValue(m.writeValueAsString(new Test()), Test.class);
        }
    }

This fails with:

Exception in thread "main" com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "renamedProp" (class example.Test), not marked as ignorable (one known property: "prop"])

I know that the best practice is to instead set the property as readonly but it's still a regression I guess?

Version Information

2.20.1

Reproduction

No response

Expected behavior

No response

Additional context

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    2.21gen-aiPR created with Generative AI (whole or assisted) (or issue for which gen-ai seems suitable)

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions