Skip to content

Commit ab9fcac

Browse files
committed
Merge branch '2.7' into 2.8
2 parents 4499bb6 + 1bef91c commit ab9fcac

File tree

4 files changed

+42
-9
lines changed

4 files changed

+42
-9
lines changed

release-notes/CREDITS

+3
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@ Dmitry Spikhalskiy (Spikhalskiy@github)
251251
* Reported #731, suggested the way to fix it: XmlAdapter result marshaling error in
252252
case of ValueType=Object
253253
(2.5.3)
254+
* Reported #1456: `TypeFactory` type resolution broken in 2.7 for generic types
255+
when using `constructType` with context
256+
(2.7.9 / 2.8.6)
254257

255258
John Meyer (jpmeyer@github)
256259
* Reported, contributed fix for #745: EnumDeserializer.deserializerForCreator() fails

release-notes/VERSION

+8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Project: jackson-databind
77
2.8.6 (not yet released)
88

99
#1453: `UntypedObjectDeserializer` does not retain `float` type (over `double`)
10+
#1456: `TypeFactory` type resolution broken in 2.7 for generic types
11+
when using `constructType` with context
1012

1113
2.8.5 (14-Nov-2016)
1214

@@ -127,6 +129,12 @@ Project: jackson-databind
127129
#1277: Add caching of resolved generic types for `TypeFactory`
128130
(requested by Andriy P)
129131

132+
2.7.9 (not released yet)
133+
134+
#1432: Off by 1 bug in PropertyValueBuffer
135+
(reported by Kevin D)
136+
#1439: NPE when using with filter id, serializing `java.util.Map` types
137+
130138
2.7.8 (26-Sep-2016)
131139

132140
#877: @JsonIgnoreProperties`: ignoring the "cause" property of `Throwable` on GAE

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

+23-5
Original file line numberDiff line numberDiff line change
@@ -651,18 +651,36 @@ public JavaType constructType(TypeReference<?> typeRef)
651651
*/
652652
@Deprecated
653653
public JavaType constructType(Type type, Class<?> contextClass) {
654-
TypeBindings bindings = (contextClass == null)
655-
? TypeBindings.emptyBindings() : constructType(contextClass).getBindings();
656-
return _fromAny(null, type, bindings);
654+
JavaType contextType = (contextClass == null) ? null : constructType(contextClass);
655+
return constructType(type, contextType);
657656
}
658657

659658
/**
660659
* @deprecated Since 2.7 (accidentally removed in 2.7.0; added back in 2.7.1)
661660
*/
662661
@Deprecated
663662
public JavaType constructType(Type type, JavaType contextType) {
664-
TypeBindings bindings = (contextType == null)
665-
? TypeBindings.emptyBindings() : contextType.getBindings();
663+
TypeBindings bindings;
664+
if (contextType == null) {
665+
bindings = TypeBindings.emptyBindings();
666+
} else {
667+
bindings = contextType.getBindings();
668+
// 16-Nov-2016, tatu: Unfortunately as per [databind#1456] this can't
669+
// be made to work for some cases used to work (even if accidentally);
670+
// however, we can try a simple heuristic to increase chances of
671+
// compatibility from 2.6 code
672+
if (type.getClass() != Class.class) {
673+
// Ok: so, ideally we would test super-interfaces if necessary;
674+
// but let's assume most if not all cases are for classes.
675+
while (bindings.isEmpty()) {
676+
contextType = contextType.getSuperClass();
677+
if (contextType == null) {
678+
break;
679+
}
680+
bindings = contextType.getBindings();
681+
}
682+
}
683+
}
666684
return _fromAny(null, type, bindings);
667685
}
668686

src/test/java/com/fasterxml/jackson/failing/GenericParameterTypeFactory1456Test.java renamed to src/test/java/com/fasterxml/jackson/databind/type/DeprecatedConstructType1456Test.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.fasterxml.jackson.failing;
1+
package com.fasterxml.jackson.databind.type;
22

33
import java.lang.reflect.Method;
44
import java.lang.reflect.Type;
@@ -8,7 +8,9 @@
88
import com.fasterxml.jackson.databind.introspect.AnnotatedMethod;
99
import com.fasterxml.jackson.databind.introspect.AnnotatedParameter;
1010

11-
public class GenericParameterTypeFactory1456Test extends BaseMapTest
11+
// Tests for [databind#1456]: resolution using methods deprecated
12+
// in 2.7, but used to work in 2.6
13+
public class DeprecatedConstructType1456Test extends BaseMapTest
1214
{
1315
public static class BaseController<Entity extends BaseEntity> {
1416
public void process(Entity entity) {}
@@ -21,8 +23,9 @@ public static class BaseEntity {}
2123
public static class ImplEntity extends BaseEntity {}
2224

2325
private final ObjectMapper MAPPER = new ObjectMapper();
24-
25-
public void testGenericParameterDirect() throws Exception
26+
27+
@SuppressWarnings("deprecation")
28+
public void testGenericResolutionUsingDeprecated() throws Exception
2629
{
2730
Method proceed = BaseController.class.getMethod("process", BaseEntity.class);
2831
Type entityType = proceed.getGenericParameterTypes()[0];
@@ -31,6 +34,7 @@ public void testGenericParameterDirect() throws Exception
3134
assertEquals(ImplEntity.class, resolvedType.getRawClass());
3235
}
3336

37+
// and this is how new code should resolve types if at all possible
3438
public void testGenericParameterViaClass() throws Exception
3539
{
3640
BeanDescription desc = MAPPER.getDeserializationConfig().introspect(

0 commit comments

Comments
 (0)