Skip to content

Commit

Permalink
Minor improvement to basetype compatibility checking (wrt #1861)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Apr 5, 2018
1 parent a5b8f63 commit 170a414
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()))
);
}
}
}

Expand Down

0 comments on commit 170a414

Please sign in to comment.