diff --git a/release-notes/CREDITS-2.x b/release-notes/CREDITS-2.x index 4feb77a474..b3795f684f 100644 --- a/release-notes/CREDITS-2.x +++ b/release-notes/CREDITS-2.x @@ -1672,6 +1672,11 @@ Kevin Baes (BaesKevin@github) as `BigDecimal` when used with `@JsonTypeInfo` and `JsonTypeInfo.As.EXISTING_PROPERTY` (2.16.0) +John Hendrikx (hjohn@github) + * Reported #3277: Combination of `@JsonUnwrapped` and `@JsonAnySetter` results in `BigDecimal` + instead of `Double` + (2.16.0) + David Schlosnagle (schlosna@github) * Contributed #4008: Optimize `ObjectNode` findValue(s) and findParent(s) fast paths (2.16.0) diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index 293634bb64..8f2d2b1423 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -29,6 +29,9 @@ Project: jackson-databind #3133: Map deserialization results in different numeric classes based on json ordering (BigDecimal / Double) when used in combination with @JsonSubTypes (reported by @mreiterer) +#3277: Combination of `@JsonUnwrapped` and `@JsonAnySetter` results in `BigDecimal` + instead of `Double` + (reported John H) #3251: Generic class with generic field of runtime type `Double` is deserialized as `BigDecimal` when used with `@JsonTypeInfo` and `JsonTypeInfo.As.EXISTING_PROPERTY` (reported by Kevin B) diff --git a/src/test/java/com/fasterxml/jackson/databind/struct/UnwrappedDoubleWithAnySetter3277Test.java b/src/test/java/com/fasterxml/jackson/databind/struct/UnwrappedDoubleWithAnySetter3277Test.java new file mode 100644 index 0000000000..0a69e0ca1b --- /dev/null +++ b/src/test/java/com/fasterxml/jackson/databind/struct/UnwrappedDoubleWithAnySetter3277Test.java @@ -0,0 +1,65 @@ +package com.fasterxml.jackson.databind.struct; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.jupiter.api.Test; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonUnwrapped; +import com.fasterxml.jackson.databind.ObjectMapper; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import static com.fasterxml.jackson.databind.BaseMapTest.newJsonMapper; + +/** + * Test to verify that [databind#3277] is fixed. + */ +public class UnwrappedDoubleWithAnySetter3277Test +{ + static class Holder { + Object value1; + + @JsonUnwrapped + Holder2 holder2; + + public Object getValue1() { + return value1; + } + + public void setValue1(Object value1) { + this.value1 = value1; + } + } + + static class Holder2 { + Map data = new HashMap<>(); + + @JsonAnyGetter + public Map getData() { + return data; + } + + @JsonAnySetter + public void setAny(String key, Object value) { + data.put(key, value); + } + } + + private final ObjectMapper MAPPER = newJsonMapper(); + + @Test + public void testIsInstanceOfDouble() throws Exception + { + Holder holder = MAPPER.readValue("{\"value1\": -60.0, \"value2\": -60.0}", Holder.class); + + // Validate type + assertEquals(Double.class, holder.value1.getClass()); + assertEquals(Double.class, holder.holder2.data.get("value2").getClass()); + // Validate value + assertEquals(-60.0, holder.value1); + assertEquals(-60.0, holder.holder2.data.get("value2")); + } +}