@@ -135,34 +135,77 @@ public void prop(String name, Base value) {
135
135
}
136
136
}
137
137
138
- static class JsonAnySetterOnMap {
139
- public int id ;
138
+ static class JsonAnySetterOnMap {
139
+ public int id ;
140
140
141
- @ JsonAnySetter
142
- protected HashMap <String , String > other = new HashMap <String , String >();
143
-
144
- @ JsonAnyGetter
145
- public Map <String , String > any () {
146
- return other ;
147
- }
141
+ @ JsonAnySetter
142
+ protected HashMap <String , String > other = new HashMap <String , String >();
148
143
149
- }
144
+ @ JsonAnyGetter
145
+ public Map <String , String > any () {
146
+ return other ;
147
+ }
148
+ }
150
149
151
- static class JsonAnySetterOnNullMap {
152
- public int id ;
150
+ static class JsonAnySetterOnNullMap {
151
+ public int id ;
153
152
154
- @ JsonAnySetter
155
- protected HashMap <String , String > other ;
153
+ @ JsonAnySetter
154
+ protected HashMap <String , String > other ;
156
155
157
- @ JsonAnyGetter
158
- public Map <String , String > any () {
159
- return other ;
160
- }
156
+ @ JsonAnyGetter
157
+ public Map <String , String > any () {
158
+ return other ;
159
+ }
160
+ }
161
161
162
- }
162
+ static class MyGeneric <T >
163
+ {
164
+ private String staticallyMappedProperty ;
165
+ private Map <T , Integer > dynamicallyMappedProperties = new HashMap <T , Integer >();
166
+
167
+ public String getStaticallyMappedProperty () {
168
+ return staticallyMappedProperty ;
169
+ }
170
+
171
+ @ JsonAnySetter
172
+ public void addDynamicallyMappedProperty (T key , int value ) {
173
+ dynamicallyMappedProperties .put (key , value );
174
+ }
163
175
176
+ public void setStaticallyMappedProperty (String staticallyMappedProperty ) {
177
+ this .staticallyMappedProperty = staticallyMappedProperty ;
178
+ }
164
179
165
- /*
180
+ @ JsonAnyGetter
181
+ public Map <T , Integer > getDynamicallyMappedProperties () {
182
+ return dynamicallyMappedProperties ;
183
+ }
184
+ }
185
+
186
+ static class MyWrapper
187
+ {
188
+ private MyGeneric <String > myStringGeneric ;
189
+ private MyGeneric <Integer > myIntegerGeneric ;
190
+
191
+ public MyGeneric <String > getMyStringGeneric () {
192
+ return myStringGeneric ;
193
+ }
194
+
195
+ public void setMyStringGeneric (MyGeneric <String > myStringGeneric ) {
196
+ this .myStringGeneric = myStringGeneric ;
197
+ }
198
+
199
+ public MyGeneric <Integer > getMyIntegerGeneric () {
200
+ return myIntegerGeneric ;
201
+ }
202
+
203
+ public void setMyIntegerGeneric (MyGeneric <Integer > myIntegerGeneric ) {
204
+ this .myIntegerGeneric = myIntegerGeneric ;
205
+ }
206
+ }
207
+
208
+ /*
166
209
/**********************************************************
167
210
/* Test methods
168
211
/**********************************************************
@@ -264,9 +307,44 @@ public void testJsonAnySetterOnNullMap() throws Exception {
264
307
JsonAnySetterOnNullMap .class );
265
308
assertEquals (2 , result .id );
266
309
assertNull (result .other );
267
- }
268
-
269
- /*
310
+ }
311
+
312
+ // [databind#1035]
313
+ public void testGenericAnySetter () throws Exception
314
+ {
315
+ ObjectMapper mapper = new ObjectMapper ();
316
+
317
+ Map <String , Integer > stringGenericMap = new HashMap <String , Integer >();
318
+ stringGenericMap .put ("testStringKey" , 5 );
319
+ Map <Integer , Integer > integerGenericMap = new HashMap <Integer , Integer >();
320
+ integerGenericMap .put (111 , 6 );
321
+
322
+ MyWrapper deserialized = mapper .readValue (aposToQuotes (
323
+ "{'myStringGeneric':{'staticallyMappedProperty':'Test','testStringKey':5},'myIntegerGeneric':{'staticallyMappedProperty':'Test2','111':6}}"
324
+ ), MyWrapper .class );
325
+ MyGeneric <String > stringGeneric = deserialized .getMyStringGeneric ();
326
+ MyGeneric <Integer > integerGeneric = deserialized .getMyIntegerGeneric ();
327
+
328
+ assertNotNull (stringGeneric );
329
+ assertEquals (stringGeneric .getStaticallyMappedProperty (), "Test" );
330
+ for (Map .Entry <String , Integer > entry : stringGeneric .getDynamicallyMappedProperties ().entrySet ()) {
331
+ assertTrue ("A key in MyGeneric<String> is not an String." , entry .getKey () instanceof String );
332
+ assertTrue ("A value in MyGeneric<Integer> is not an Integer." , entry .getValue () instanceof Integer );
333
+ }
334
+ assertEquals (stringGeneric .getDynamicallyMappedProperties (), stringGenericMap );
335
+
336
+ assertNotNull (integerGeneric );
337
+ assertEquals (integerGeneric .getStaticallyMappedProperty (), "Test2" );
338
+ for (Map .Entry <Integer , Integer > entry : integerGeneric .getDynamicallyMappedProperties ().entrySet ()) {
339
+ Object key = entry .getKey ();
340
+ assertEquals ("A key in MyGeneric<Integer> is not an Integer." , Integer .class , key .getClass ());
341
+ Object value = entry .getValue ();
342
+ assertEquals ("A value in MyGeneric<Integer> is not an Integer." , Integer .class , value .getClass ());
343
+ }
344
+ assertEquals (integerGeneric .getDynamicallyMappedProperties (), integerGenericMap );
345
+ }
346
+
347
+ /*
270
348
/**********************************************************
271
349
/* Private helper methods
272
350
/**********************************************************
0 commit comments