Skip to content

Commit 170a414

Browse files
committed
Minor improvement to basetype compatibility checking (wrt #1861)
1 parent a5b8f63 commit 170a414

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/main/java/com/fasterxml/jackson/databind/jsontype/impl/StdTypeResolverBuilder.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.fasterxml.jackson.databind.annotation.NoClass;
99
import com.fasterxml.jackson.databind.cfg.MapperConfig;
1010
import com.fasterxml.jackson.databind.jsontype.*;
11+
import com.fasterxml.jackson.databind.util.ClassUtil;
1112

1213
/**
1314
* Default {@link TypeResolverBuilder} implementation.
@@ -135,8 +136,21 @@ public TypeDeserializer buildTypeDeserializer(DeserializationConfig config,
135136
|| (_defaultImpl == NoClass.class)) {
136137
defaultImpl = config.getTypeFactory().constructType(_defaultImpl);
137138
} else {
138-
defaultImpl = config.getTypeFactory()
139-
.constructSpecializedType(baseType, _defaultImpl);
139+
if (baseType.hasRawClass(_defaultImpl)) { // common enough to check
140+
defaultImpl = baseType;
141+
} else if (baseType.isTypeOrSuperTypeOf(_defaultImpl)) {
142+
// most common case with proper base type...
143+
defaultImpl = config.getTypeFactory()
144+
.constructSpecializedType(baseType, _defaultImpl);
145+
} else {
146+
// 05-Apr-2018, tatu: [databind#1861] Not sure what would be the best way
147+
// to handle, but for 2.9, let's consider case of "sibling" defaultImpl...
148+
// ... Ugh. Not declared to throw `JsonMappingException`, so...
149+
throw new IllegalArgumentException(
150+
String.format("Invalid \"defaultImpl\" (%s): not a subtype of basetype (%s)",
151+
ClassUtil.nameOf(_defaultImpl), ClassUtil.nameOf(baseType.getRawClass()))
152+
);
153+
}
140154
}
141155
}
142156

0 commit comments

Comments
 (0)