Skip to content

Commit 131cb2e

Browse files
authored
Add passing test to close #3277 (#4259)
1 parent 810c979 commit 131cb2e

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

release-notes/CREDITS-2.x

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,6 +1672,11 @@ Kevin Baes (BaesKevin@github)
16721672
as `BigDecimal` when used with `@JsonTypeInfo` and `JsonTypeInfo.As.EXISTING_PROPERTY`
16731673
(2.16.0)
16741674

1675+
John Hendrikx (hjohn@github)
1676+
* Reported #3277: Combination of `@JsonUnwrapped` and `@JsonAnySetter` results in `BigDecimal`
1677+
instead of `Double`
1678+
(2.16.0)
1679+
16751680
David Schlosnagle (schlosna@github)
16761681
* Contributed #4008: Optimize `ObjectNode` findValue(s) and findParent(s) fast paths
16771682
(2.16.0)

release-notes/VERSION-2.x

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ Project: jackson-databind
2929
#3133: Map deserialization results in different numeric classes based on
3030
json ordering (BigDecimal / Double) when used in combination with @JsonSubTypes
3131
(reported by @mreiterer)
32+
#3277: Combination of `@JsonUnwrapped` and `@JsonAnySetter` results in `BigDecimal`
33+
instead of `Double`
34+
(reported John H)
3235
#3251: Generic class with generic field of runtime type `Double` is deserialized
3336
as `BigDecimal` when used with `@JsonTypeInfo` and `JsonTypeInfo.As.EXISTING_PROPERTY`
3437
(reported by Kevin B)
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.fasterxml.jackson.databind.struct;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
import org.junit.jupiter.api.Test;
7+
8+
import com.fasterxml.jackson.annotation.JsonAnyGetter;
9+
import com.fasterxml.jackson.annotation.JsonAnySetter;
10+
import com.fasterxml.jackson.annotation.JsonUnwrapped;
11+
import com.fasterxml.jackson.databind.ObjectMapper;
12+
13+
import static org.junit.jupiter.api.Assertions.assertEquals;
14+
15+
import static com.fasterxml.jackson.databind.BaseMapTest.newJsonMapper;
16+
17+
/**
18+
* Test to verify that [databind#3277] is fixed.
19+
*/
20+
public class UnwrappedDoubleWithAnySetter3277Test
21+
{
22+
static class Holder {
23+
Object value1;
24+
25+
@JsonUnwrapped
26+
Holder2 holder2;
27+
28+
public Object getValue1() {
29+
return value1;
30+
}
31+
32+
public void setValue1(Object value1) {
33+
this.value1 = value1;
34+
}
35+
}
36+
37+
static class Holder2 {
38+
Map<String, Object> data = new HashMap<>();
39+
40+
@JsonAnyGetter
41+
public Map<String, Object> getData() {
42+
return data;
43+
}
44+
45+
@JsonAnySetter
46+
public void setAny(String key, Object value) {
47+
data.put(key, value);
48+
}
49+
}
50+
51+
private final ObjectMapper MAPPER = newJsonMapper();
52+
53+
@Test
54+
public void testIsInstanceOfDouble() throws Exception
55+
{
56+
Holder holder = MAPPER.readValue("{\"value1\": -60.0, \"value2\": -60.0}", Holder.class);
57+
58+
// Validate type
59+
assertEquals(Double.class, holder.value1.getClass());
60+
assertEquals(Double.class, holder.holder2.data.get("value2").getClass());
61+
// Validate value
62+
assertEquals(-60.0, holder.value1);
63+
assertEquals(-60.0, holder.holder2.data.get("value2"));
64+
}
65+
}

0 commit comments

Comments
 (0)