diff --git a/src/main/java/com/fasterxml/jackson/databind/jsontype/impl/StdTypeResolverBuilder.java b/src/main/java/com/fasterxml/jackson/databind/jsontype/impl/StdTypeResolverBuilder.java index f3ce303c6d..04c8f1f06c 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsontype/impl/StdTypeResolverBuilder.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsontype/impl/StdTypeResolverBuilder.java @@ -8,6 +8,7 @@ import com.fasterxml.jackson.databind.annotation.NoClass; import com.fasterxml.jackson.databind.cfg.MapperConfig; import com.fasterxml.jackson.databind.jsontype.*; +import com.fasterxml.jackson.databind.util.ClassUtil; /** * Default {@link TypeResolverBuilder} implementation. @@ -135,8 +136,21 @@ public TypeDeserializer buildTypeDeserializer(DeserializationConfig config, || (_defaultImpl == NoClass.class)) { defaultImpl = config.getTypeFactory().constructType(_defaultImpl); } else { - defaultImpl = config.getTypeFactory() - .constructSpecializedType(baseType, _defaultImpl); + if (baseType.hasRawClass(_defaultImpl)) { // common enough to check + defaultImpl = baseType; + } else if (baseType.isTypeOrSuperTypeOf(_defaultImpl)) { + // most common case with proper base type... + defaultImpl = config.getTypeFactory() + .constructSpecializedType(baseType, _defaultImpl); + } else { + // 05-Apr-2018, tatu: [databind#1861] Not sure what would be the best way + // to handle, but for 2.9, let's consider case of "sibling" defaultImpl... + // ... Ugh. Not declared to throw `JsonMappingException`, so... + throw new IllegalArgumentException( + String.format("Invalid \"defaultImpl\" (%s): not a subtype of basetype (%s)", + ClassUtil.nameOf(_defaultImpl), ClassUtil.nameOf(baseType.getRawClass())) + ); + } } }