@@ -944,7 +944,7 @@ public Object handleWeirdNumberValue(Class<?> targetClass, Number value,
944
944
if ((key == null ) || targetClass .isInstance (key )) {
945
945
return key ;
946
946
}
947
- throw weirdNumberException (value , targetClass , String . format (
947
+ throw weirdNumberException (value , targetClass , _format (
948
948
"DeserializationProblemHandler.handleWeirdNumberValue() for type %s returned value of type %s" ,
949
949
targetClass , key .getClass ()));
950
950
}
@@ -953,6 +953,28 @@ public Object handleWeirdNumberValue(Class<?> targetClass, Number value,
953
953
throw weirdNumberException (value , targetClass , msg );
954
954
}
955
955
956
+ public Object handleWeirdNativeValue (JavaType targetType , Object badValue ,
957
+ JsonParser p )
958
+ throws IOException
959
+ {
960
+ LinkedNode <DeserializationProblemHandler > h = _config .getProblemHandlers ();
961
+ final Class <?> raw = targetType .getRawClass ();
962
+ for (; h != null ; h = h .next ()) {
963
+ // Can bail out if it's handled
964
+ Object goodValue = h .value ().handleWeirdNativeValue (this , targetType , badValue , p );
965
+ if (goodValue != DeserializationProblemHandler .NOT_HANDLED ) {
966
+ // Sanity check for broken handlers, otherwise nasty to debug:
967
+ if ((goodValue == null ) || raw .isInstance (goodValue )) {
968
+ return goodValue ;
969
+ }
970
+ throw JsonMappingException .from (p , _format (
971
+ "DeserializationProblemHandler.handleWeirdNativeValue() for type %s returned value of type %s" ,
972
+ targetType , goodValue .getClass ()));
973
+ }
974
+ }
975
+ throw weirdNativeValueException (badValue , raw );
976
+ }
977
+
956
978
/**
957
979
* Method that deserializers should call if they fail to instantiate value
958
980
* due to lack of viable instantiator (usually creator, that is, constructor
@@ -1531,6 +1553,24 @@ public JsonMappingException weirdNumberException(Number value, Class<?> instClas
1531
1553
value , instClass );
1532
1554
}
1533
1555
1556
+ /**
1557
+ * Helper method for constructing exception to indicate that input JSON
1558
+ * token of type "native value" (see {@link JsonToken#VALUE_EMBEDDED_OBJECT})
1559
+ * is of incompatible type (and there is no delegating creator or such to use)
1560
+ * and can not be used to construct value of specified type (usually POJO).
1561
+ * Note that most of the time this method should NOT be called; instead,
1562
+ * {@link #handleWeirdNativeValue} should be called which will call this method
1563
+ *
1564
+ * @since 2.9
1565
+ */
1566
+ public JsonMappingException weirdNativeValueException (Object value , Class <?> instClass )
1567
+ {
1568
+ return InvalidFormatException .from (_parser , String .format (
1569
+ "Cannot deserialize value of type %s from native value (`JsonToken.VALUE_EMBEDDED_OBJECT`) of type %s: incompatible types" ,
1570
+ ClassUtil .nameOf (instClass ), ClassUtil .classNameOf (value )),
1571
+ value , instClass );
1572
+ }
1573
+
1534
1574
/**
1535
1575
* Helper method for constructing instantiation exception for specified type,
1536
1576
* to indicate problem with physically constructing instance of
0 commit comments