Skip to content

Commit 9e2f76e

Browse files
committed
Fix #1186
1 parent f2bb0df commit 9e2f76e

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

release-notes/VERSION

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

99
#1178: `@JsonSerialize(contentAs=superType)` behavior disallowed in 2.7
10+
#1186: SimpleAbstractTypeResolver breaks generic parameters
11+
(reported by tobiash@github)
1012
#1189: Converter called twice results in ClassCastException
1113
(reported by carrino@github)
1214
#1191: Non-matching quotes used in error message for date parsing

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

+17-3
Original file line numberDiff line numberDiff line change
@@ -364,11 +364,12 @@ public JavaType constructSpecializedType(JavaType baseType, Class<?> subclass)
364364
}
365365
}
366366
// (3) Sub-class does not take type parameters -- just resolve subtype
367-
if (subclass.getTypeParameters().length == 0) {
367+
int typeParamCount = subclass.getTypeParameters().length;
368+
if (typeParamCount == 0) {
368369
newType = _fromClass(null, subclass, TypeBindings.emptyBindings());
369370
break;
370371
}
371-
372+
372373
// If not, we'll need to do more thorough forward+backwards resolution. Sigh.
373374
// !!! TODO (as of 28-Jan-2016, at least)
374375

@@ -390,7 +391,20 @@ public JavaType constructSpecializedType(JavaType baseType, Class<?> subclass)
390391
if (newType == null) {
391392
// But otherwise gets bit tricky, as we need to partially resolve the type hierarchy
392393
// (hopefully passing null Class for root is ok)
393-
newType = _fromClass(null, subclass, TypeBindings.emptyBindings());
394+
TypeBindings tb = null;
395+
396+
// 14-Apr-2016, tatu: One possible short-cut; if type parameter counts
397+
// match, chances are they ought to match. Let's take our chances...
398+
if (baseType.containedTypeCount() == typeParamCount) {
399+
if (typeParamCount == 1) {
400+
tb = TypeBindings.create(subclass, baseType.containedType(0));
401+
} else if (typeParamCount == 2) {
402+
tb = TypeBindings.create(subclass, baseType.containedType(0),
403+
baseType.containedType(1));
404+
}
405+
}
406+
newType = _fromClass(null, subclass,
407+
(tb == null) ? TypeBindings.emptyBindings() : tb);
394408
}
395409
} while (false);
396410

src/test/java/com/fasterxml/jackson/failing/AbstracTypeMapping1186Test.java renamed to src/test/java/com/fasterxml/jackson/databind/jsontype/AbstracTypeMapping1186Test.java

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

33
import java.util.List;
44

0 commit comments

Comments
 (0)