|
8 | 8 | import com.fasterxml.jackson.databind.annotation.NoClass;
|
9 | 9 | import com.fasterxml.jackson.databind.cfg.MapperConfig;
|
10 | 10 | import com.fasterxml.jackson.databind.jsontype.*;
|
| 11 | +import com.fasterxml.jackson.databind.util.ClassUtil; |
11 | 12 |
|
12 | 13 | /**
|
13 | 14 | * Default {@link TypeResolverBuilder} implementation.
|
@@ -135,8 +136,21 @@ public TypeDeserializer buildTypeDeserializer(DeserializationConfig config,
|
135 | 136 | || (_defaultImpl == NoClass.class)) {
|
136 | 137 | defaultImpl = config.getTypeFactory().constructType(_defaultImpl);
|
137 | 138 | } 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 | + } |
140 | 154 | }
|
141 | 155 | }
|
142 | 156 |
|
|
0 commit comments