@@ -914,7 +914,7 @@ public Object handleWeirdStringValue(Class<?> targetClass, String value,
914914 Object instance = h .value ().handleWeirdStringValue (this , targetClass , value , msg );
915915 if (instance != DeserializationProblemHandler .NOT_HANDLED ) {
916916 // Sanity check for broken handlers, otherwise nasty to debug:
917- if (( instance == null ) || targetClass . isInstance ( instance )) {
917+ if (_isCompatible ( targetClass , instance )) {
918918 return instance ;
919919 }
920920 throw weirdStringException (value , targetClass , String .format (
@@ -959,7 +959,7 @@ public Object handleWeirdNumberValue(Class<?> targetClass, Number value,
959959 Object key = h .value ().handleWeirdNumberValue (this , targetClass , value , msg );
960960 if (key != DeserializationProblemHandler .NOT_HANDLED ) {
961961 // Sanity check for broken handlers, otherwise nasty to debug:
962- if (( key == null ) || targetClass . isInstance ( key )) {
962+ if (_isCompatible ( targetClass , key )) {
963963 return key ;
964964 }
965965 throw weirdNumberException (value , targetClass , String .format (
@@ -1000,7 +1000,7 @@ public Object handleMissingInstantiator(Class<?> instClass, JsonParser p,
10001000 instClass , p , msg );
10011001 if (instance != DeserializationProblemHandler .NOT_HANDLED ) {
10021002 // Sanity check for broken handlers, otherwise nasty to debug:
1003- if (( instance == null ) || instClass . isInstance ( instance )) {
1003+ if (_isCompatible ( instClass , instance )) {
10041004 return instance ;
10051005 }
10061006 throw instantiationException (instClass , String .format (
@@ -1039,7 +1039,7 @@ public Object handleInstantiationProblem(Class<?> instClass, Object argument,
10391039 Object instance = h .value ().handleInstantiationProblem (this , instClass , argument , t );
10401040 if (instance != DeserializationProblemHandler .NOT_HANDLED ) {
10411041 // Sanity check for broken handlers, otherwise nasty to debug:
1042- if (( instance == null ) || instClass . isInstance ( instance )) {
1042+ if (_isCompatible ( instClass , instance )) {
10431043 return instance ;
10441044 }
10451045 throw instantiationException (instClass , String .format (
@@ -1102,7 +1102,7 @@ public Object handleUnexpectedToken(Class<?> instClass, JsonToken t,
11021102 Object instance = h .value ().handleUnexpectedToken (this ,
11031103 instClass , t , p , msg );
11041104 if (instance != DeserializationProblemHandler .NOT_HANDLED ) {
1105- if (( instance == null ) || instClass . isInstance ( instance )) {
1105+ if (_isCompatible ( instClass , instance )) {
11061106 return instance ;
11071107 }
11081108 reportMappingException ("DeserializationProblemHandler.handleUnexpectedToken() for type %s returned value of type %s" ,
@@ -1170,6 +1170,19 @@ public JavaType handleUnknownTypeId(JavaType baseType, String id,
11701170 throw unknownTypeIdException (baseType , id , extraDesc );
11711171 }
11721172
1173+ /**
1174+ * @since 2.9.2
1175+ */
1176+ protected boolean _isCompatible (Class <?> target , Object value )
1177+ {
1178+ if ((value == null ) || target .isInstance (value )) {
1179+ return true ;
1180+ }
1181+ // [databind#1767]: Make sure to allow wrappers for primitive fields
1182+ return target .isPrimitive ()
1183+ && ClassUtil .wrapperType (target ).isInstance (value );
1184+ }
1185+
11731186 /*
11741187 /**********************************************************
11751188 /* Methods for problem reporting, in cases where recovery
0 commit comments