diff --git a/release-notes/CREDITS b/release-notes/CREDITS index fe0563a5ec..ed5dc0b218 100644 --- a/release-notes/CREDITS +++ b/release-notes/CREDITS @@ -509,3 +509,7 @@ Ari Fogel (arifogel@github) Andriy Plokhotnyuk (plokhotnyuk@github) * Requested #1277: Add caching of resolved generic types for `TypeFactory` (2.8.0) + +Arek Gabiga (arekgabiga@github) + * Reported #1297: Deserialization of generic type with Map.class + (2.8.1) diff --git a/release-notes/VERSION b/release-notes/VERSION index 49b2a6f6ec..84e73058d9 100644 --- a/release-notes/VERSION +++ b/release-notes/VERSION @@ -12,6 +12,8 @@ Project: jackson-databind #1289: Optimize construction of `ArrayList`, `LinkedHashMap` instances #1291: Backward-incompatible behaviour of 2.8: deserializing enum types with two static factory methods fail by default +#1297: Deserialization of generic type with Map.class + (reported by Arek G) 2.8.0 (04-Jul-2016) diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/impl/CreatorCollector.java b/src/main/java/com/fasterxml/jackson/databind/deser/impl/CreatorCollector.java index 70d0417196..e4b6779abd 100644 --- a/src/main/java/com/fasterxml/jackson/databind/deser/impl/CreatorCollector.java +++ b/src/main/java/com/fasterxml/jackson/databind/deser/impl/CreatorCollector.java @@ -441,8 +441,8 @@ public JavaType getParameterType(int index) { return _base.getParameterType(index); } - @SuppressWarnings("deprecation") @Override + @Deprecated public Type getGenericParameterType(int index) { return _base.getGenericParameterType(index); } diff --git a/src/main/java/com/fasterxml/jackson/databind/type/TypeFactory.java b/src/main/java/com/fasterxml/jackson/databind/type/TypeFactory.java index e5153beca5..219b774a7c 100644 --- a/src/main/java/com/fasterxml/jackson/databind/type/TypeFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/type/TypeFactory.java @@ -281,7 +281,7 @@ public Class findClass(String className) throws ClassNotFoundException Throwable prob = null; ClassLoader loader = this.getClassLoader(); if (loader == null) { - loader = Thread.currentThread().getContextClassLoader(); + loader = Thread.currentThread().getContextClassLoader(); } if (loader != null) { try { @@ -1013,7 +1013,7 @@ private JavaType _mapType(Class rawClass, TypeBindings bindings, JavaType superClass, JavaType[] superInterfaces) { JavaType kt, vt; - + // 28-May-2015, tatu: Properties are special, as per [databind#810]; fake "correct" parameter sig if (rawClass == Properties.class) { kt = vt = CORE_TYPE_STRING; @@ -1307,6 +1307,10 @@ protected JavaType[] _resolveSuperInterfaces(ClassStack context, Class rawTyp protected JavaType _fromWellKnownClass(ClassStack context, Class rawType, TypeBindings bindings, JavaType superClass, JavaType[] superInterfaces) { + if (bindings == null) { + bindings = TypeBindings.emptyBindings(); + } + // Quite simple when we resolving exact class/interface; start with that if (rawType == Map.class) { return _mapType(rawType, bindings, superClass, superInterfaces); diff --git a/src/test/java/com/fasterxml/jackson/databind/type/JavaType76Test.java b/src/test/java/com/fasterxml/jackson/databind/type/JavaType76Test.java deleted file mode 100644 index 9378e17351..0000000000 --- a/src/test/java/com/fasterxml/jackson/databind/type/JavaType76Test.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.fasterxml.jackson.databind.type; - -import java.util.*; - -import com.fasterxml.jackson.databind.*; -import com.fasterxml.jackson.databind.type.TypeFactory; - -/** - * Failing test related to [databind#76] - */ -public class JavaType76Test extends BaseMapTest -{ - @SuppressWarnings("serial") - static class HashTree extends HashMap> { } - - public void testRecursiveType() - { - TypeFactory tf = TypeFactory.defaultInstance(); - JavaType type = tf.constructType(HashTree.class); - assertNotNull(type); - } -} diff --git a/src/test/java/com/fasterxml/jackson/databind/type/TestLocalType609.java b/src/test/java/com/fasterxml/jackson/databind/type/TestLocalTypes.java similarity index 95% rename from src/test/java/com/fasterxml/jackson/databind/type/TestLocalType609.java rename to src/test/java/com/fasterxml/jackson/databind/type/TestLocalTypes.java index 6d208b6129..1399f0e641 100644 --- a/src/test/java/com/fasterxml/jackson/databind/type/TestLocalType609.java +++ b/src/test/java/com/fasterxml/jackson/databind/type/TestLocalTypes.java @@ -5,7 +5,7 @@ /** * Failing test related to [databind#609] */ -public class TestLocalType609 extends BaseMapTest +public class TestLocalTypes extends BaseMapTest { static class EntityContainer { RuleForm entity; diff --git a/src/test/java/com/fasterxml/jackson/databind/type/TestTypeBindings.java b/src/test/java/com/fasterxml/jackson/databind/type/TestTypeBindings.java index f2b9e4af93..7af37e8cd0 100644 --- a/src/test/java/com/fasterxml/jackson/databind/type/TestTypeBindings.java +++ b/src/test/java/com/fasterxml/jackson/databind/type/TestTypeBindings.java @@ -29,14 +29,17 @@ public Set>> entrySet() { } } } - + + // for [databind#76] + @SuppressWarnings("serial") + static class HashTree extends HashMap> { } + /* /********************************************************** /* Test methods /********************************************************** */ - // [JACKSON-677] public void testInnerType() throws Exception { TypeFactory tf = TypeFactory.defaultInstance(); @@ -49,4 +52,12 @@ public void testInnerType() throws Exception JavaType vt2 = valueType.getContentType(); assertEquals(Object.class, vt2.getRawClass()); } + + // for [databind#76] + public void testRecursiveType() + { + TypeFactory tf = TypeFactory.defaultInstance(); + JavaType type = tf.constructType(HashTree.class); + assertNotNull(type); + } } diff --git a/src/test/java/com/fasterxml/jackson/databind/type/TestTypeFactory.java b/src/test/java/com/fasterxml/jackson/databind/type/TestTypeFactory.java index e5183a0664..dd075e5738 100644 --- a/src/test/java/com/fasterxml/jackson/databind/type/TestTypeFactory.java +++ b/src/test/java/com/fasterxml/jackson/databind/type/TestTypeFactory.java @@ -70,7 +70,11 @@ static class StringListBean { static class CollectionLike { } static class MapLike { } - + + static class Wrapper1297 { + public T content; + } + /* /********************************************************** /* Unit tests @@ -565,5 +569,14 @@ public void testCacheClearing() tf.clearCache(); assertEquals(0, tf._typeCache.size()); } + + // for [databind#1297] + public void testRawMapType() + { + TypeFactory tf = TypeFactory.defaultInstance().withModifier(null); // to get a new copy + + JavaType type = tf.constructParametricType(Wrapper1297.class, Map.class); + assertNotNull(type); + assertEquals(Wrapper1297.class, type.getRawClass()); + } } - \ No newline at end of file