@@ -770,7 +770,7 @@ public <T> T readValue(JsonParser p, Class<T> type) throws IOException {
770
770
public <T > T readValue (JsonParser p , JavaType type ) throws IOException {
771
771
JsonDeserializer <Object > deser = findRootValueDeserializer (type );
772
772
if (deser == null ) {
773
- throw mappingException ("Could not find JsonDeserializer for type %s" , type );
773
+ throw mappingException ("Could not find JsonDeserializer for type " + type );
774
774
}
775
775
return (T ) deser .deserialize (p , this );
776
776
}
@@ -795,8 +795,9 @@ public <T> T readPropertyValue(JsonParser p, BeanProperty prop, JavaType type) t
795
795
JsonDeserializer <Object > deser = findContextualValueDeserializer (type , prop );
796
796
if (deser == null ) {
797
797
String propName = (prop == null ) ? "NULL" : ("'" +prop .getName ()+"'" );
798
- throw mappingException ("Could not find JsonDeserializer for type %s (via property %s)" ,
799
- type , propName );
798
+ throw mappingException (String .format (
799
+ "Could not find JsonDeserializer for type %s (via property %s)" ,
800
+ type , propName ));
800
801
}
801
802
return (T ) deser .deserialize (p , this );
802
803
}
@@ -1059,6 +1060,71 @@ public Object handleInstantiationProblem(Class<?> instClass, Object argument,
1059
1060
throw instantiationException (instClass , t );
1060
1061
}
1061
1062
1063
+ /**
1064
+ * Method that deserializers should call if the first token of the value to
1065
+ * deserialize is of unexpected type (that is, type of token that deserializer
1066
+ * can not handle). This could occur, for example, if a Number deserializer
1067
+ * encounter {@link JsonToken#START_ARRAY} instead of
1068
+ * {@link JsonToken#VALUE_NUMBER_INT} or {@link JsonToken#VALUE_NUMBER_FLOAT}.
1069
+ *
1070
+ * @param instClass Type that was to be instantiated
1071
+ * @param p Parser that points to the JSON value to decode
1072
+ *
1073
+ * @return Object that should be constructed, if any; has to be of type <code>instClass</code>
1074
+ *
1075
+ * @since 2.8
1076
+ */
1077
+ public Object handleUnexpectedToken (Class <?> instClass , JsonParser p )
1078
+ throws IOException
1079
+ {
1080
+ return handleUnexpectedToken (instClass , p .getCurrentToken (), p , null );
1081
+ }
1082
+
1083
+ /**
1084
+ * Method that deserializers should call if the first token of the value to
1085
+ * deserialize is of unexpected type (that is, type of token that deserializer
1086
+ * can not handle). This could occur, for example, if a Number deserializer
1087
+ * encounter {@link JsonToken#START_ARRAY} instead of
1088
+ * {@link JsonToken#VALUE_NUMBER_INT} or {@link JsonToken#VALUE_NUMBER_FLOAT}.
1089
+ *
1090
+ * @param instClass Type that was to be instantiated
1091
+ * @param p Parser that points to the JSON value to decode
1092
+ *
1093
+ * @return Object that should be constructed, if any; has to be of type <code>instClass</code>
1094
+ *
1095
+ * @since 2.8
1096
+ */
1097
+ public Object handleUnexpectedToken (Class <?> instClass , JsonToken t ,
1098
+ JsonParser p ,
1099
+ String msg , Object ... msgArgs )
1100
+ throws IOException
1101
+ {
1102
+ if (msgArgs .length > 0 ) {
1103
+ msg = String .format (msg , msgArgs );
1104
+ }
1105
+ /*
1106
+ LinkedNode<DeserializationProblemHandler> h = _config.getProblemHandlers();
1107
+ while (h != null) {
1108
+ Object instance = h.value().handleUnexpectedToken(this,
1109
+ instClass, t, p, msg);
1110
+ if (instance != DeserializationProblemHandler.NOT_HANDLED) {
1111
+ if ((instance == null) || instClass.isInstance(instance)) {
1112
+ return instance;
1113
+ }
1114
+ throw mappingException(String.format(
1115
+ "DeserializationProblemHandler.handleUnexpectedToken() for type %s returned value of type %s",
1116
+ instClass, instance.getClass()));
1117
+ }
1118
+ h = h.next();
1119
+ }
1120
+ */
1121
+ if (msg == null ) {
1122
+ msg = String .format ("Can not deserialize instance of %s out of %s token" ,
1123
+ _calcName (instClass ), t );
1124
+ }
1125
+ throw mappingException (msg );
1126
+ }
1127
+
1062
1128
/**
1063
1129
* Method that deserializers should call if they encounter a type id
1064
1130
* (for polymorphic deserialization) that can not be resolved to an
@@ -1123,7 +1189,7 @@ public void reportWrongTokenException(JsonParser p,
1123
1189
JsonToken expToken , String msg , Object ... msgArgs )
1124
1190
throws JsonMappingException
1125
1191
{
1126
- if (msgArgs .length > 0 ) {
1192
+ if (( msg != null ) && ( msgArgs .length > 0 ) ) {
1127
1193
msg = String .format (msg , msgArgs );
1128
1194
}
1129
1195
throw wrongTokenException (p , expToken , msg );
@@ -1166,50 +1232,18 @@ public void reportMappingException(String msg, Object... msgArgs)
1166
1232
throw mappingException (msg );
1167
1233
}
1168
1234
1169
- /**
1170
- * @since 2.8
1171
- */
1172
- public void reportMappingException (Class <?> targetClass , JsonToken t ) throws JsonMappingException {
1173
- throw mappingException (targetClass , t );
1174
- }
1175
-
1176
- /**
1177
- * @since 2.8
1178
- */
1179
- public void reportMappingException (Class <?> targetClass ) throws JsonMappingException {
1180
- throw mappingException (targetClass );
1181
- }
1182
-
1183
1235
/*
1184
1236
/**********************************************************
1185
1237
/* Methods for constructing exceptions, "untyped"
1186
1238
/**********************************************************
1187
1239
*/
1188
-
1189
- /**
1190
- * Helper method for constructing generic mapping exception for specified type
1191
- *
1192
- * @deprecated Since 2.8 use {@link #reportMappingException(Class)} instead
1193
- */
1194
- @ Deprecated
1195
- public JsonMappingException mappingException (Class <?> targetClass ) {
1196
- return mappingException (targetClass , _parser .getCurrentToken ());
1197
- }
1198
-
1199
- /**
1200
- * @deprecated Since 2.8 use {@link #reportMappingException(Class, JsonToken)} instead
1201
- */
1202
- @ Deprecated
1203
- public JsonMappingException mappingException (Class <?> targetClass , JsonToken token ) {
1204
- return JsonMappingException .from (_parser ,
1205
- String .format ("Can not deserialize instance of %s out of %s token" ,
1206
- _calcName (targetClass ), token ));
1207
- }
1208
1240
1209
1241
/**
1210
- * @deprecated Since 2.8 use {@link #reportMappingException(String, Object...)} instead
1242
+ * Helper method for constructing generic mapping exception with specified
1243
+ * message and current location information
1244
+ *
1245
+ * @since 2.6
1211
1246
*/
1212
- @ Deprecated
1213
1247
public JsonMappingException mappingException (String message ) {
1214
1248
return JsonMappingException .from (getParser (), message );
1215
1249
}
@@ -1219,17 +1253,34 @@ public JsonMappingException mappingException(String message) {
1219
1253
* message and current location information
1220
1254
*
1221
1255
* @since 2.6
1222
- *
1223
- * @deprecated Since 2.8 use {@link #reportMappingException(String, Object...)} instead
1224
1256
*/
1225
- @ Deprecated
1226
1257
public JsonMappingException mappingException (String msgTemplate , Object ... args ) {
1227
1258
if (args != null && args .length > 0 ) {
1228
1259
msgTemplate = String .format (msgTemplate , args );
1229
1260
}
1230
1261
return JsonMappingException .from (getParser (), msgTemplate );
1231
1262
}
1232
1263
1264
+ /**
1265
+ * Helper method for constructing generic mapping exception for specified type
1266
+ *
1267
+ * @deprecated Since 2.8 use {@link #handleUnexpectedToken(Class, JsonParser)} instead
1268
+ */
1269
+ @ Deprecated
1270
+ public JsonMappingException mappingException (Class <?> targetClass ) {
1271
+ return mappingException (targetClass , _parser .getCurrentToken ());
1272
+ }
1273
+
1274
+ /**
1275
+ * @deprecated Since 2.8 use {@link #handleUnexpectedToken(Class, JsonParser)} instead
1276
+ */
1277
+ @ Deprecated
1278
+ public JsonMappingException mappingException (Class <?> targetClass , JsonToken token ) {
1279
+ return JsonMappingException .from (_parser ,
1280
+ String .format ("Can not deserialize instance of %s out of %s token" ,
1281
+ _calcName (targetClass ), token ));
1282
+ }
1283
+
1233
1284
/*
1234
1285
/**********************************************************
1235
1286
/* Methods for constructing semantic exceptions; usually not
@@ -1359,7 +1410,7 @@ public JsonMappingException unknownTypeIdException(JavaType baseType, String typ
1359
1410
1360
1411
/*
1361
1412
/**********************************************************
1362
- /* Methods for constructing semantic exceptions
1413
+ /* Deprecated exception factory methods
1363
1414
/**********************************************************
1364
1415
*/
1365
1416
@@ -1393,7 +1444,7 @@ public JsonMappingException endOfInputException(Class<?> instClass) {
1393
1444
1394
1445
/*
1395
1446
/**********************************************************
1396
- /* Overridable internal methods
1447
+ /* Other internal methods
1397
1448
/**********************************************************
1398
1449
*/
1399
1450
@@ -1415,12 +1466,6 @@ protected DateFormat getDateFormat()
1415
1466
protected String determineClassName (Object instance ) {
1416
1467
return ClassUtil .getClassDescription (instance );
1417
1468
}
1418
-
1419
- /*
1420
- /**********************************************************
1421
- /* Other internal methods
1422
- /**********************************************************
1423
- */
1424
1469
1425
1470
protected String _calcName (Class <?> cls ) {
1426
1471
if (cls .isArray ()) {
0 commit comments