@@ -914,7 +914,7 @@ public Object handleWeirdStringValue(Class<?> targetClass, String value,
914
914
Object instance = h .value ().handleWeirdStringValue (this , targetClass , value , msg );
915
915
if (instance != DeserializationProblemHandler .NOT_HANDLED ) {
916
916
// Sanity check for broken handlers, otherwise nasty to debug:
917
- if (( instance == null ) || targetClass . isInstance ( instance )) {
917
+ if (_isCompatible ( targetClass , instance )) {
918
918
return instance ;
919
919
}
920
920
throw weirdStringException (value , targetClass , String .format (
@@ -959,7 +959,7 @@ public Object handleWeirdNumberValue(Class<?> targetClass, Number value,
959
959
Object key = h .value ().handleWeirdNumberValue (this , targetClass , value , msg );
960
960
if (key != DeserializationProblemHandler .NOT_HANDLED ) {
961
961
// Sanity check for broken handlers, otherwise nasty to debug:
962
- if (( key == null ) || targetClass . isInstance ( key )) {
962
+ if (_isCompatible ( targetClass , key )) {
963
963
return key ;
964
964
}
965
965
throw weirdNumberException (value , targetClass , String .format (
@@ -1000,7 +1000,7 @@ public Object handleMissingInstantiator(Class<?> instClass, JsonParser p,
1000
1000
instClass , p , msg );
1001
1001
if (instance != DeserializationProblemHandler .NOT_HANDLED ) {
1002
1002
// Sanity check for broken handlers, otherwise nasty to debug:
1003
- if (( instance == null ) || instClass . isInstance ( instance )) {
1003
+ if (_isCompatible ( instClass , instance )) {
1004
1004
return instance ;
1005
1005
}
1006
1006
throw instantiationException (instClass , String .format (
@@ -1039,7 +1039,7 @@ public Object handleInstantiationProblem(Class<?> instClass, Object argument,
1039
1039
Object instance = h .value ().handleInstantiationProblem (this , instClass , argument , t );
1040
1040
if (instance != DeserializationProblemHandler .NOT_HANDLED ) {
1041
1041
// Sanity check for broken handlers, otherwise nasty to debug:
1042
- if (( instance == null ) || instClass . isInstance ( instance )) {
1042
+ if (_isCompatible ( instClass , instance )) {
1043
1043
return instance ;
1044
1044
}
1045
1045
throw instantiationException (instClass , String .format (
@@ -1102,7 +1102,7 @@ public Object handleUnexpectedToken(Class<?> instClass, JsonToken t,
1102
1102
Object instance = h .value ().handleUnexpectedToken (this ,
1103
1103
instClass , t , p , msg );
1104
1104
if (instance != DeserializationProblemHandler .NOT_HANDLED ) {
1105
- if (( instance == null ) || instClass . isInstance ( instance )) {
1105
+ if (_isCompatible ( instClass , instance )) {
1106
1106
return instance ;
1107
1107
}
1108
1108
reportMappingException ("DeserializationProblemHandler.handleUnexpectedToken() for type %s returned value of type %s" ,
@@ -1170,6 +1170,19 @@ public JavaType handleUnknownTypeId(JavaType baseType, String id,
1170
1170
throw unknownTypeIdException (baseType , id , extraDesc );
1171
1171
}
1172
1172
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
+
1173
1186
/*
1174
1187
/**********************************************************
1175
1188
/* Methods for problem reporting, in cases where recovery
0 commit comments