From 96b74393f401ac0b38a72b8000ab9eb941e5f3d5 Mon Sep 17 00:00:00 2001 From: joohyukkim Date: Fri, 8 Nov 2024 23:51:21 +0900 Subject: [PATCH 1/3] Initial fix for #4639 --- .../databind/deser/BeanDeserializer.java | 4 +- .../databind/deser/SettableAnyProperty.java | 7 +++ .../AnySetterFieldWithCreator4639Test.java | 44 +++++++++++++++++-- 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializer.java b/src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializer.java index e9b2481afb..982ef05377 100644 --- a/src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializer.java @@ -506,7 +506,9 @@ protected Object _deserializeUsingPropertyBased(final JsonParser p, final Deseri if (_anySetter != null) { try { // [databind#4639] Since 2.18.1 AnySetter might not part of the creator, but just some field. - if (_anySetter.isFieldType()) { + if (_anySetter.isFieldType() || + // [databind#4639] 2.18.2: Also should account for setter type :-/ + _anySetter.isSetterType()) { buffer.bufferAnyProperty(_anySetter, propName, _anySetter.deserialize(p, ctxt)); } else { buffer.bufferAnyParameterProperty(_anySetter, propName, _anySetter.deserialize(p, ctxt)); diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/SettableAnyProperty.java b/src/main/java/com/fasterxml/jackson/databind/deser/SettableAnyProperty.java index 11998275f4..d606d86101 100644 --- a/src/main/java/com/fasterxml/jackson/databind/deser/SettableAnyProperty.java +++ b/src/main/java/com/fasterxml/jackson/databind/deser/SettableAnyProperty.java @@ -201,6 +201,13 @@ Object readResolve() { */ public boolean isFieldType() { return _setterIsField; } + /** + * Method called to check whether this property is method + * + * @return 2.18.2 + */ + public boolean isSetterType() { return _setter instanceof AnnotatedMethod; } + /** * Create an instance of value to pass through Creator parameter. * diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/AnySetterFieldWithCreator4639Test.java b/src/test/java/com/fasterxml/jackson/databind/deser/AnySetterFieldWithCreator4639Test.java index 1320aee6bc..878ccbe683 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/AnySetterFieldWithCreator4639Test.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/AnySetterFieldWithCreator4639Test.java @@ -1,14 +1,16 @@ package com.fasterxml.jackson.databind.deser; +import java.util.HashMap; import java.util.Map; +import org.junit.jupiter.api.Test; + import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.testutil.DatabindTestUtil; -import org.junit.jupiter.api.Test; - import static org.junit.jupiter.api.Assertions.assertEquals; // [databind#4639] 2.18.1 : regression when using @JsonAnySetter outside of @JsonCreator @@ -30,13 +32,49 @@ public Bean(@JsonProperty("b") int b, @JsonProperty("d") int d) { } } + public static class SomeBean { + final int b; + final int d; + final Map any = new HashMap<>(); + + @JsonCreator + public SomeBean(@JsonProperty("b") int b, @JsonProperty("d") int d) { + this.b = b; + this.d = d; + } + + @JsonAnySetter + public void setAny(String name, Object value) { + any.put(name, value); + } + } + + final ObjectMapper MAPPER = newJsonMapper(); + @Test public void testJsonAnySetter() throws Exception { String json = "{\"a\":1,\"b\":2,\"c\":3,\"d\":4,\"e\":5,\"f\":6}"; - Bean bean = newJsonMapper().readValue(json, Bean.class); + Bean bean = MAPPER.readValue(json, Bean.class); + assertEquals(2, bean.b); + assertEquals(4, bean.d); + + // failed with: + // org.opentest4j.AssertionFailedError: + // Expected :{b=2, c=3, e=5, f=6} + // Actual :{e=5, f=6} + assertEquals(mapOf("a", 1, "c", 3, "e", 5, "f", 6), bean.any); + } + + @Test + public void testJsonAnySetterWithField() + throws Exception + { + String json = "{\"a\":1,\"b\":2,\"c\":3,\"d\":4,\"e\":5,\"f\":6}"; + + SomeBean bean = MAPPER.readValue(json, SomeBean.class); assertEquals(2, bean.b); assertEquals(4, bean.d); From 31303345ab1b3a744458ceb2cc329f769b703f78 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Fri, 8 Nov 2024 15:19:00 -0800 Subject: [PATCH 2/3] Update release notes --- release-notes/VERSION-2.x | 3 +++ 1 file changed, 3 insertions(+) diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index cb3726c68d..07f50ff3af 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -13,6 +13,9 @@ Project: jackson-databind #4788: `EnumFeature.WRITE_ENUMS_TO_LOWERCASE` overrides `@JsonProperty` values (reported by Mike M) (fix by Joo-Hyuk K) +#4790: Fix `@JsonAnySetter` issue with "setter" method (related to #4639) + (reported by @bsa01) + (fix by Joo-Hyuk K) 2.18.1 (28-Oct-2024) From d38b2b6fada2c10b57123fd6647a238f956ccd48 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Fri, 8 Nov 2024 15:24:02 -0800 Subject: [PATCH 3/3] Fixing earlier probs with release notes --- release-notes/VERSION-2.x | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index 07f50ff3af..8099ad4279 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -19,13 +19,6 @@ Project: jackson-databind 2.18.1 (28-Oct-2024) -#4741: When `Include.NON_DEFAULT` setting is used on POJO, empty values - are not included in json if default is `null` - (reported by @ragnhov) - (fix by Joo-Hyuk K) -#4749: Fixed a problem with `StdDelegatingSerializer#serializeWithType` looking up the serializer - with the wrong argument - (fix by wrongwrong) #4508: Deserialized JsonAnySetter field in Kotlin data class is null (reported by @MaximValeev) (fix by Joo-Hyuk K) @@ -37,6 +30,14 @@ Project: jackson-databind #4724: Deserialization behavior change with Records, `@JsonCreator` and `@JsonValue` between 2.17 and 2.18 (reported by Antti L) +#4727: Eclipse having issues due`module-info` class "lost" on 2.18.0 jars +#4741: When `Include.NON_DEFAULT` setting is used on POJO, empty values + are not included in json if default is `null` + (reported by @ragnhov) + (fix by Joo-Hyuk K) +#4749: Fixed a problem with `StdDelegatingSerializer#serializeWithType` looking up the serializer + with the wrong argument + (fix by wrongwrong) 2.18.0 (26-Sep-2024)