@@ -168,47 +168,39 @@ public TypeDeserializer buildTypeDeserializer(DeserializationConfig config,
168168 throw new IllegalStateException ("Do not know how to construct standard type serializer for inclusion type: " +_includeAs );
169169 }
170170
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 ) {
180174 // 20-Mar-2016, tatu: It is important to do specialization go through
181175 // TypeFactory to ensure proper resolution; with 2.7 and before, direct
182176 // call to JavaType was used, but that cannot work reliably with 2.7
183177 // 20-Mar-2016, tatu: Can finally add a check for type compatibility BUT
184178 // if so, need to add explicit checks for marker types. Not ideal, but
185179 // 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 ;
209187 }
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 ;
210202 }
211- return defaultImpl ;
203+ return null ;
212204 }
213205
214206 /*
0 commit comments