Skip to content

Commit db0eadb

Browse files
committed
Fixed #1297
1 parent 26f2669 commit db0eadb

File tree

8 files changed

+42
-30
lines changed

8 files changed

+42
-30
lines changed

release-notes/CREDITS

+4
Original file line numberDiff line numberDiff line change
@@ -509,3 +509,7 @@ Ari Fogel (arifogel@github)
509509
Andriy Plokhotnyuk (plokhotnyuk@github)
510510
* Requested #1277: Add caching of resolved generic types for `TypeFactory`
511511
(2.8.0)
512+
513+
Arek Gabiga (arekgabiga@github)
514+
* Reported #1297: Deserialization of generic type with Map.class
515+
(2.8.1)

release-notes/VERSION

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Project: jackson-databind
1212
#1289: Optimize construction of `ArrayList`, `LinkedHashMap` instances
1313
#1291: Backward-incompatible behaviour of 2.8: deserializing enum types
1414
with two static factory methods fail by default
15+
#1297: Deserialization of generic type with Map.class
16+
(reported by Arek G)
1517

1618
2.8.0 (04-Jul-2016)
1719

src/main/java/com/fasterxml/jackson/databind/deser/impl/CreatorCollector.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,8 @@ public JavaType getParameterType(int index) {
441441
return _base.getParameterType(index);
442442
}
443443

444-
@SuppressWarnings("deprecation")
445444
@Override
445+
@Deprecated
446446
public Type getGenericParameterType(int index) {
447447
return _base.getGenericParameterType(index);
448448
}

src/main/java/com/fasterxml/jackson/databind/type/TypeFactory.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ public Class<?> findClass(String className) throws ClassNotFoundException
281281
Throwable prob = null;
282282
ClassLoader loader = this.getClassLoader();
283283
if (loader == null) {
284-
loader = Thread.currentThread().getContextClassLoader();
284+
loader = Thread.currentThread().getContextClassLoader();
285285
}
286286
if (loader != null) {
287287
try {
@@ -1013,7 +1013,7 @@ private JavaType _mapType(Class<?> rawClass, TypeBindings bindings,
10131013
JavaType superClass, JavaType[] superInterfaces)
10141014
{
10151015
JavaType kt, vt;
1016-
1016+
10171017
// 28-May-2015, tatu: Properties are special, as per [databind#810]; fake "correct" parameter sig
10181018
if (rawClass == Properties.class) {
10191019
kt = vt = CORE_TYPE_STRING;
@@ -1307,6 +1307,10 @@ protected JavaType[] _resolveSuperInterfaces(ClassStack context, Class<?> rawTyp
13071307
protected JavaType _fromWellKnownClass(ClassStack context, Class<?> rawType, TypeBindings bindings,
13081308
JavaType superClass, JavaType[] superInterfaces)
13091309
{
1310+
if (bindings == null) {
1311+
bindings = TypeBindings.emptyBindings();
1312+
}
1313+
13101314
// Quite simple when we resolving exact class/interface; start with that
13111315
if (rawType == Map.class) {
13121316
return _mapType(rawType, bindings, superClass, superInterfaces);

src/test/java/com/fasterxml/jackson/databind/type/JavaType76Test.java

-22
This file was deleted.

src/test/java/com/fasterxml/jackson/databind/type/TestLocalType609.java renamed to src/test/java/com/fasterxml/jackson/databind/type/TestLocalTypes.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/**
66
* Failing test related to [databind#609]
77
*/
8-
public class TestLocalType609 extends BaseMapTest
8+
public class TestLocalTypes extends BaseMapTest
99
{
1010
static class EntityContainer {
1111
RuleForm entity;

src/test/java/com/fasterxml/jackson/databind/type/TestTypeBindings.java

+13-2
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,17 @@ public Set<java.util.Map.Entry<K, Collection<V>>> entrySet() {
2929
}
3030
}
3131
}
32-
32+
33+
// for [databind#76]
34+
@SuppressWarnings("serial")
35+
static class HashTree<K, V> extends HashMap<K, HashTree<K, V>> { }
36+
3337
/*
3438
/**********************************************************
3539
/* Test methods
3640
/**********************************************************
3741
*/
3842

39-
// [JACKSON-677]
4043
public void testInnerType() throws Exception
4144
{
4245
TypeFactory tf = TypeFactory.defaultInstance();
@@ -49,4 +52,12 @@ public void testInnerType() throws Exception
4952
JavaType vt2 = valueType.getContentType();
5053
assertEquals(Object.class, vt2.getRawClass());
5154
}
55+
56+
// for [databind#76]
57+
public void testRecursiveType()
58+
{
59+
TypeFactory tf = TypeFactory.defaultInstance();
60+
JavaType type = tf.constructType(HashTree.class);
61+
assertNotNull(type);
62+
}
5263
}

src/test/java/com/fasterxml/jackson/databind/type/TestTypeFactory.java

+15-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ static class StringListBean {
7070

7171
static class CollectionLike<E> { }
7272
static class MapLike<K,V> { }
73-
73+
74+
static class Wrapper1297<T> {
75+
public T content;
76+
}
77+
7478
/*
7579
/**********************************************************
7680
/* Unit tests
@@ -565,5 +569,14 @@ public void testCacheClearing()
565569
tf.clearCache();
566570
assertEquals(0, tf._typeCache.size());
567571
}
572+
573+
// for [databind#1297]
574+
public void testRawMapType()
575+
{
576+
TypeFactory tf = TypeFactory.defaultInstance().withModifier(null); // to get a new copy
577+
578+
JavaType type = tf.constructParametricType(Wrapper1297.class, Map.class);
579+
assertNotNull(type);
580+
assertEquals(Wrapper1297.class, type.getRawClass());
581+
}
568582
}
569-

0 commit comments

Comments
 (0)