Skip to content

Commit

Permalink
Fix #1186
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Apr 14, 2016
1 parent f2bb0df commit 9e2f76e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
2 changes: 2 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Project: jackson-databind
2.7.4 (not yet released)

#1178: `@JsonSerialize(contentAs=superType)` behavior disallowed in 2.7
#1186: SimpleAbstractTypeResolver breaks generic parameters
(reported by tobiash@github)
#1189: Converter called twice results in ClassCastException
(reported by carrino@github)
#1191: Non-matching quotes used in error message for date parsing
Expand Down
20 changes: 17 additions & 3 deletions src/main/java/com/fasterxml/jackson/databind/type/TypeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -364,11 +364,12 @@ public JavaType constructSpecializedType(JavaType baseType, Class<?> subclass)
}
}
// (3) Sub-class does not take type parameters -- just resolve subtype
if (subclass.getTypeParameters().length == 0) {
int typeParamCount = subclass.getTypeParameters().length;
if (typeParamCount == 0) {
newType = _fromClass(null, subclass, TypeBindings.emptyBindings());
break;
}

// If not, we'll need to do more thorough forward+backwards resolution. Sigh.
// !!! TODO (as of 28-Jan-2016, at least)

Expand All @@ -390,7 +391,20 @@ public JavaType constructSpecializedType(JavaType baseType, Class<?> subclass)
if (newType == null) {
// But otherwise gets bit tricky, as we need to partially resolve the type hierarchy
// (hopefully passing null Class for root is ok)
newType = _fromClass(null, subclass, TypeBindings.emptyBindings());
TypeBindings tb = null;

// 14-Apr-2016, tatu: One possible short-cut; if type parameter counts
// match, chances are they ought to match. Let's take our chances...
if (baseType.containedTypeCount() == typeParamCount) {
if (typeParamCount == 1) {
tb = TypeBindings.create(subclass, baseType.containedType(0));
} else if (typeParamCount == 2) {
tb = TypeBindings.create(subclass, baseType.containedType(0),
baseType.containedType(1));
}
}
newType = _fromClass(null, subclass,
(tb == null) ? TypeBindings.emptyBindings() : tb);
}
} while (false);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.fasterxml.jackson.failing;
package com.fasterxml.jackson.databind.jsontype;

import java.util.List;

Expand Down

0 comments on commit 9e2f76e

Please sign in to comment.