aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTatu Saloranta <tatu.saloranta@iki.fi>2020-07-16 19:37:18 -0700
committerTatu Saloranta <tatu.saloranta@iki.fi>2020-07-16 19:37:18 -0700
commit94b7cba7a5910ab8f156679863a546cdb37433dc (patch)
treebe22dab6bcd072671ddd90d12d5839337b1317d9 /src
parent925c7c11858db33a95870256b1e9931e4e33beea (diff)
downloadjackson-databind-94b7cba7a5910ab8f156679863a546cdb37433dc.tar.gz
Fixed #2796 (second part of fix to apply TypeModifiers on `TypeFactory.constructParametricType()`
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/fasterxml/jackson/databind/type/TypeFactory.java5
-rw-r--r--src/test/java/com/fasterxml/jackson/databind/module/TestTypeModifiers.java32
-rw-r--r--src/test/java/com/fasterxml/jackson/databind/type/TestTypeFactory.java2
3 files changed, 28 insertions, 11 deletions
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 17d1d3196..553acccec 100644
--- a/src/main/java/com/fasterxml/jackson/databind/type/TypeFactory.java
+++ b/src/main/java/com/fasterxml/jackson/databind/type/TypeFactory.java
@@ -1049,7 +1049,10 @@ public class TypeFactory // note: was final in 2.9, removed from 2.10
*/
public JavaType constructParametricType(Class<?> rawType, JavaType... parameterTypes)
{
- return _fromClass(null, rawType, TypeBindings.create(rawType, parameterTypes));
+ // 16-Jul-2020, tatu: Since we do not call `_fromAny()`, need to make
+ // sure `TypeModifier`s are applied:
+ JavaType resultType = _fromClass(null, rawType, TypeBindings.create(rawType, parameterTypes));
+ return _applyModifiers(rawType, resultType);
}
/**
diff --git a/src/test/java/com/fasterxml/jackson/databind/module/TestTypeModifiers.java b/src/test/java/com/fasterxml/jackson/databind/module/TestTypeModifiers.java
index fe8728507..5aa14fbba 100644
--- a/src/test/java/com/fasterxml/jackson/databind/module/TestTypeModifiers.java
+++ b/src/test/java/com/fasterxml/jackson/databind/module/TestTypeModifiers.java
@@ -6,6 +6,7 @@ import java.lang.reflect.Type;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.json.JsonMapper;
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.module.SimpleDeserializers;
@@ -205,22 +206,23 @@ public class TestTypeModifiers extends BaseMapTest
return type;
}
}
-
+
/*
/**********************************************************
/* Unit tests
/**********************************************************
*/
+ private final ObjectMapper MAPPER_WITH_MODIFIER = JsonMapper.builder()
+ .typeFactory(TypeFactory.defaultInstance().withModifier(new MyTypeModifier()))
+ .build();
+
/**
* Basic test for ensuring that we can get "xxx-like" types recognized.
*/
public void testMapLikeTypeConstruction() throws Exception
{
- ObjectMapper mapper = new ObjectMapper();
- mapper.setTypeFactory(mapper.getTypeFactory().withModifier(new MyTypeModifier()));
-
- JavaType type = mapper.constructType(MyMapLikeType.class);
+ JavaType type = MAPPER_WITH_MODIFIER.constructType(MyMapLikeType.class);
assertTrue(type.isMapLikeType());
// also, must have resolved type info
JavaType param = ((MapLikeType) type).getKeyType();
@@ -231,6 +233,21 @@ public class TestTypeModifiers extends BaseMapTest
assertSame(Integer.class, param.getRawClass());
}
+ public void testMapLikeTypeViaParametric() throws Exception
+ {
+ // [databind#2796]: should refine with another call too
+ JavaType type = MAPPER_WITH_MODIFIER.getTypeFactory().constructParametricType(MapMarker.class,
+ new Class<?>[] { String.class, Double.class });
+ assertTrue(type.isMapLikeType());
+ JavaType param = ((MapLikeType) type).getKeyType();
+ assertNotNull(param);
+ assertSame(String.class, param.getRawClass());
+
+ param = ((MapLikeType) type).getContentType();
+ assertNotNull(param);
+ assertSame(Double.class, param.getRawClass());
+ }
+
// [databind#2395] Can trigger problem this way too
// NOTE: oddly enough, seems to ONLY fail
public void testTypeResolutionForRecursive() throws Exception
@@ -247,10 +264,7 @@ public class TestTypeModifiers extends BaseMapTest
public void testCollectionLikeTypeConstruction() throws Exception
{
- ObjectMapper mapper = new ObjectMapper();
- mapper.setTypeFactory(mapper.getTypeFactory().withModifier(new MyTypeModifier()));
-
- JavaType type = mapper.constructType(MyCollectionLikeType.class);
+ JavaType type = MAPPER_WITH_MODIFIER.constructType(MyCollectionLikeType.class);
assertTrue(type.isCollectionLikeType());
JavaType param = ((CollectionLikeType) type).getContentType();
assertNotNull(param);
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 35ab67214..e78c15d1a 100644
--- a/src/test/java/com/fasterxml/jackson/databind/type/TestTypeFactory.java
+++ b/src/test/java/com/fasterxml/jackson/databind/type/TestTypeFactory.java
@@ -13,7 +13,7 @@ import com.fasterxml.jackson.databind.*;
*/
public class TestTypeFactory
extends BaseMapTest
-{
+{
/*
/**********************************************************
/* Helper types