FasterXML / jackson-databind

General data-binding package for Jackson (2.x): works on streaming API (core) implementation(s)
Apache License 2.0
3.53k stars 1.38k forks source link

JsonAnySetter handling changed recently? #4795

Closed alesj closed 1 week ago

alesj commented 1 week ago

Search before asking

Describe the bug

This used to work for me (in 2.17.2):

    record AnyTester(Map<String, Object> p) {
        AnyTester {
            if (p == null) {
                p = new LinkedHashMap<>();
            }
        }

        @JsonAnySetter
        public void setAnyUnknownProperty(String key, Object value) {
            p.put(key, value);
        }
    }

    @Test
    public void testAnyTester() throws Exception {
        AnyTester at = OBJECT_MAPPER.readValue("{\"foo\":\"bar\"}", AnyTester.class);
        Assertions.assertEquals("bar", at.p().get("foo"));
    }

Now there is no foo=bar entry in the p map.

Version Information

2.18.1

Reproduction

Just run the test above.

Expected behavior

p should have foo=bar entry.

Additional context

No response

JooHyukKim commented 1 week ago

Might be related to #4639 could you try 2.18.2 (latest)?

alesj commented 1 week ago

@JooHyukKim where can I find 2.18.2 ? (https://central.sonatype.com/search?q=jackson-databind)

alesj commented 1 week ago

@JooHyukKim where can I find 2.18.2 ? (https://central.sonatype.com/search?q=jackson-databind)

Ah, OK ... I guess I should just build the current repo (which points to 2.19.0-SNAPSHOT ... which confused me)

JooHyukKim commented 1 week ago

Ah yes, sorry I should've mentioned that. Thanks @alesj !

alesj commented 1 week ago

@JooHyukKim yup, that seems to fix it, tnx! (the test is now passing ...)

Closing the issue now, as fixed by the #4639

JooHyukKim commented 1 week ago

Phew! Awesome. Thank you for reporting @alesj !

cowtowncoder commented 1 week ago

Marking as duplicate of #4639. Thank you for verifying @alesj .