5
5
6
6
import com .fasterxml .jackson .annotation .JsonCreator ;
7
7
import com .fasterxml .jackson .annotation .JsonProperty ;
8
+
8
9
import com .fasterxml .jackson .core .type .TypeReference ;
10
+
9
11
import com .fasterxml .jackson .databind .*;
10
12
11
13
// Test(s) to check for handling of Static Factory Creator bindings
@@ -55,8 +57,43 @@ public String toString() {
55
57
}
56
58
}
57
59
60
+ // [databind#2895]
61
+ static class SimpleWrapper2895 <T > {
62
+ final T value ;
63
+
64
+ SimpleWrapper2895 (T value ) {
65
+ this .value = value ;
66
+ }
67
+
68
+ @ JsonCreator (mode = JsonCreator .Mode .DELEGATING )
69
+ public static <T > SimpleWrapper2895 <T > fromJson (JsonSimpleWrapper2895 <T > value ) {
70
+ return new SimpleWrapper2895 <>(value .object );
71
+ }
72
+ }
73
+
74
+ static final class JsonSimpleWrapper2895 <T > {
75
+ @ JsonProperty ("object" )
76
+ public T object ;
77
+ }
78
+
79
+ static class Account2895 {
80
+ private long id ;
81
+ private String name ;
82
+
83
+ @ JsonCreator
84
+ public Account2895 (@ JsonProperty ("name" ) String name ,
85
+ @ JsonProperty ("id" ) long id ) {
86
+ this .id = id ;
87
+ this .name = name ;
88
+ }
89
+
90
+ public String getName () { return name ; }
91
+ public long getId () { return id ; }
92
+ }
93
+
58
94
private final ObjectMapper MAPPER = newJsonMapper ();
59
95
96
+ // [databind#2894]
60
97
public void testIssue2894 () throws Exception
61
98
{
62
99
Wrapper <Value > src = new Wrapper <>(Arrays .asList (new Value (1 ), new Value (2 )));
@@ -65,4 +102,16 @@ public void testIssue2894() throws Exception
65
102
new TypeReference <Wrapper <Value >>() {});
66
103
assertEquals (src .values , output .values );
67
104
}
105
+
106
+ // [databind#2895]
107
+ public void testIssue2895 () throws Exception
108
+ {
109
+ SimpleWrapper2895 <Account2895 > wrapper = MAPPER
110
+ .readerFor (new TypeReference <SimpleWrapper2895 <Account2895 >>() {})
111
+ .readValue ("{\" object\" :{\" id\" :1,\" name\" :\" name1\" }}" );
112
+
113
+ Account2895 account = wrapper .value ;
114
+ assertEquals (1 , account .getId ());
115
+ assertEquals ("name1" , account .getName ());
116
+ }
68
117
}
0 commit comments