6
6
import com .fasterxml .jackson .core .*;
7
7
import com .fasterxml .jackson .databind .*;
8
8
import com .fasterxml .jackson .databind .annotation .JsonSerialize ;
9
+ import com .fasterxml .jackson .databind .json .JsonMapper ;
9
10
import com .fasterxml .jackson .databind .jsontype .TypeDeserializer ;
10
11
import com .fasterxml .jackson .databind .jsontype .TypeSerializer ;
11
12
import com .fasterxml .jackson .databind .module .SimpleDeserializers ;
@@ -205,22 +206,23 @@ public JavaType modifyType(JavaType type, Type jdkType, TypeBindings bindings, T
205
206
return type ;
206
207
}
207
208
}
208
-
209
+
209
210
/*
210
211
/**********************************************************
211
212
/* Unit tests
212
213
/**********************************************************
213
214
*/
214
215
216
+ private final ObjectMapper MAPPER_WITH_MODIFIER = JsonMapper .builder ()
217
+ .typeFactory (TypeFactory .defaultInstance ().withModifier (new MyTypeModifier ()))
218
+ .build ();
219
+
215
220
/**
216
221
* Basic test for ensuring that we can get "xxx-like" types recognized.
217
222
*/
218
223
public void testMapLikeTypeConstruction () throws Exception
219
224
{
220
- ObjectMapper mapper = new ObjectMapper ();
221
- mapper .setTypeFactory (mapper .getTypeFactory ().withModifier (new MyTypeModifier ()));
222
-
223
- JavaType type = mapper .constructType (MyMapLikeType .class );
225
+ JavaType type = MAPPER_WITH_MODIFIER .constructType (MyMapLikeType .class );
224
226
assertTrue (type .isMapLikeType ());
225
227
// also, must have resolved type info
226
228
JavaType param = ((MapLikeType ) type ).getKeyType ();
@@ -231,6 +233,21 @@ public void testMapLikeTypeConstruction() throws Exception
231
233
assertSame (Integer .class , param .getRawClass ());
232
234
}
233
235
236
+ public void testMapLikeTypeViaParametric () throws Exception
237
+ {
238
+ // [databind#2796]: should refine with another call too
239
+ JavaType type = MAPPER_WITH_MODIFIER .getTypeFactory ().constructParametricType (MapMarker .class ,
240
+ new Class <?>[] { String .class , Double .class });
241
+ assertTrue (type .isMapLikeType ());
242
+ JavaType param = ((MapLikeType ) type ).getKeyType ();
243
+ assertNotNull (param );
244
+ assertSame (String .class , param .getRawClass ());
245
+
246
+ param = ((MapLikeType ) type ).getContentType ();
247
+ assertNotNull (param );
248
+ assertSame (Double .class , param .getRawClass ());
249
+ }
250
+
234
251
// [databind#2395] Can trigger problem this way too
235
252
// NOTE: oddly enough, seems to ONLY fail
236
253
public void testTypeResolutionForRecursive () throws Exception
@@ -247,10 +264,7 @@ public void setupModule(SetupContext context) {
247
264
248
265
public void testCollectionLikeTypeConstruction () throws Exception
249
266
{
250
- ObjectMapper mapper = new ObjectMapper ();
251
- mapper .setTypeFactory (mapper .getTypeFactory ().withModifier (new MyTypeModifier ()));
252
-
253
- JavaType type = mapper .constructType (MyCollectionLikeType .class );
267
+ JavaType type = MAPPER_WITH_MODIFIER .constructType (MyCollectionLikeType .class );
254
268
assertTrue (type .isCollectionLikeType ());
255
269
JavaType param = ((CollectionLikeType ) type ).getContentType ();
256
270
assertNotNull (param );
0 commit comments