@@ -168,47 +168,39 @@ public TypeDeserializer buildTypeDeserializer(DeserializationConfig config,
168
168
throw new IllegalStateException ("Do not know how to construct standard type serializer for inclusion type: " +_includeAs );
169
169
}
170
170
171
- protected JavaType defineDefaultImpl (DeserializationConfig config , JavaType baseType ) {
172
- JavaType defaultImpl ;
173
- if (_defaultImpl == null ) {
174
- if (config .isEnabled (MapperFeature .USE_BASE_TYPE_AS_DEFAULT_IMPL ) && !baseType .isAbstract ()) {
175
- defaultImpl = baseType ;
176
- } else {
177
- defaultImpl = null ;
178
- }
179
- } else {
171
+ protected JavaType defineDefaultImpl (DeserializationConfig config , JavaType baseType )
172
+ {
173
+ if (_defaultImpl != null ) {
180
174
// 20-Mar-2016, tatu: It is important to do specialization go through
181
175
// TypeFactory to ensure proper resolution; with 2.7 and before, direct
182
176
// call to JavaType was used, but that cannot work reliably with 2.7
183
177
// 20-Mar-2016, tatu: Can finally add a check for type compatibility BUT
184
178
// if so, need to add explicit checks for marker types. Not ideal, but
185
179
// seems like a reasonable compromise.
186
- if ((_defaultImpl == Void .class )
187
- || (_defaultImpl == NoClass .class )) {
188
- defaultImpl = config .getTypeFactory ().constructType (_defaultImpl );
189
- } else {
190
- if (baseType .hasRawClass (_defaultImpl )) { // common enough to check
191
- defaultImpl = baseType ;
192
- } else if (baseType .isTypeOrSuperTypeOf (_defaultImpl )) {
193
- // most common case with proper base type...
194
- defaultImpl = config .getTypeFactory ()
195
- .constructSpecializedType (baseType , _defaultImpl );
196
- } else {
197
- // 05-Apr-2018, tatu: As [databind#1565] and [databind#1861] need to allow
198
- // some cases of seemingly incompatible `defaultImpl`. Easiest to just clear
199
- // the setting.
200
-
201
- /*
202
- throw new IllegalArgumentException(
203
- String.format("Invalid \"defaultImpl\" (%s): not a subtype of basetype (%s)",
204
- ClassUtil.nameOf(_defaultImpl), ClassUtil.nameOf(baseType.getRawClass()))
205
- );
206
- */
207
- defaultImpl = null ;
208
- }
180
+ if ((_defaultImpl == Void .class ) || (_defaultImpl == NoClass .class )) {
181
+ // 18-Sep-2021, tatu: This has specific meaning: these two markers will
182
+ // be used to conjure `null` value out of invalid type ids
183
+ return config .getTypeFactory ().constructType (_defaultImpl );
184
+ }
185
+ if (baseType .hasRawClass (_defaultImpl )) { // tiny optimization
186
+ return baseType ;
209
187
}
188
+ if (baseType .isTypeOrSuperTypeOf (_defaultImpl )) {
189
+ // most common case with proper base type...
190
+ return config .getTypeFactory ()
191
+ .constructSpecializedType (baseType , _defaultImpl );
192
+ }
193
+ if (baseType .hasRawClass (_defaultImpl )) {
194
+ return baseType ;
195
+ }
196
+ }
197
+ // use base type as default should always be used as the last choice.
198
+ if (config .isEnabled (MapperFeature .USE_BASE_TYPE_AS_DEFAULT_IMPL )
199
+ && !baseType .isAbstract ()) {
200
+ // still can not resolve by default impl, fall back to use base type as default impl
201
+ return baseType ;
210
202
}
211
- return defaultImpl ;
203
+ return null ;
212
204
}
213
205
214
206
/*
0 commit comments