Skip to content

Commit bd3c312

Browse files
committed
Convert last remaining DeserializationContext.mappingException() usage to .reportMappingException()
1 parent 1e5fd12 commit bd3c312

16 files changed

+69
-39
lines changed

src/main/java/com/fasterxml/jackson/databind/DeserializationContext.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1010,13 +1010,16 @@ public void reportMappingException(Class<?> targetClass) throws JsonMappingExcep
10101010

10111011
/**
10121012
* Helper method for constructing generic mapping exception for specified type
1013+
*
1014+
* @deprecated Since 2.8 use {@link #reportMappingException(Class)} instead
10131015
*/
1016+
@Deprecated
10141017
public JsonMappingException mappingException(Class<?> targetClass) {
10151018
return mappingException(targetClass, _parser.getCurrentToken());
10161019
}
10171020

10181021
/**
1019-
* @deprecated Since 2.8 use {@link #reportMappingException(String, Object...)} instead
1022+
* @deprecated Since 2.8 use {@link #reportMappingException(Class, JsonToken)} instead
10201023
*/
10211024
@Deprecated
10221025
public JsonMappingException mappingException(Class<?> targetClass, JsonToken token) {

src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializer.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -500,9 +500,10 @@ protected Object deserializeFromNull(JsonParser p, DeserializationContext ctxt)
500500
p2.close();
501501
return ob;
502502
}
503-
throw ctxt.mappingException(handledType());
503+
ctxt.reportMappingException(handledType());
504+
return null;
504505
}
505-
506+
506507
/*
507508
/**********************************************************
508509
/* Deserializing when we have to consider an active View

src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerBase.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1302,7 +1302,8 @@ public Object deserializeFromArray(JsonParser p, DeserializationContext ctxt) th
13021302
ctxt.reportMappingException(handledType(), JsonToken.START_ARRAY);
13031303
return null;
13041304
}
1305-
throw ctxt.mappingException(handledType());
1305+
ctxt.reportMappingException(handledType());
1306+
return null;
13061307
}
13071308

13081309
public Object deserializeFromEmbedded(JsonParser p, DeserializationContext ctxt)

src/main/java/com/fasterxml/jackson/databind/deser/BuilderBasedDeserializer.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,11 @@ public final Object deserialize(JsonParser p, DeserializationContext ctxt)
164164
// these only work if there's a (delegating) creator...
165165
return finishBuild(ctxt, deserializeFromArray(p, ctxt));
166166
case FIELD_NAME:
167-
case END_OBJECT: // added to resolve [JACKSON-319], possible related issues
167+
case END_OBJECT:
168168
return finishBuild(ctxt, deserializeFromObject(p, ctxt));
169169
default:
170-
throw ctxt.mappingException(handledType());
170+
ctxt.reportMappingException(handledType());
171+
return null;
171172
}
172173
}
173174

src/main/java/com/fasterxml/jackson/databind/deser/std/CollectionDeserializer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,8 @@ protected final Collection<Object> handleNonArray(JsonParser p, DeserializationC
324324
((_unwrapSingle == null) &&
325325
ctxt.isEnabled(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY));
326326
if (!canWrap) {
327-
throw ctxt.mappingException(_collectionType.getRawClass());
327+
ctxt.reportMappingException(_collectionType.getRawClass());
328+
return null;
328329
}
329330
JsonDeserializer<Object> valueDes = _valueDeserializer;
330331
final TypeDeserializer typeDeser = _valueTypeDeserializer;

src/main/java/com/fasterxml/jackson/databind/deser/std/EnumDeserializer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,8 @@ protected Object _deserializeOther(JsonParser p, DeserializationContext ctxt) th
211211
}
212212
return parsed;
213213
}
214-
throw ctxt.mappingException(_enumClass());
214+
ctxt.reportMappingException(_enumClass());
215+
return null;
215216
}
216217

217218
protected void _failOnNumber(DeserializationContext ctxt, JsonParser p, int index)

src/main/java/com/fasterxml/jackson/databind/deser/std/EnumSetDeserializer.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ public EnumSet<?> deserialize(JsonParser p, DeserializationContext ctxt) throws
137137
* deserializers)
138138
*/
139139
if (t == JsonToken.VALUE_NULL) {
140-
throw ctxt.mappingException(_enumClass);
140+
ctxt.reportMappingException(_enumClass);
141+
return null;
141142
}
142143
Enum<?> value = _enumDeserializer.deserialize(p, ctxt);
143144
/* 24-Mar-2012, tatu: As per [JACKSON-810], may actually get nulls;
@@ -177,13 +178,15 @@ protected EnumSet<?> handleNonArray(JsonParser p, DeserializationContext ctxt)
177178
ctxt.isEnabled(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY));
178179

179180
if (!canWrap) {
180-
throw ctxt.mappingException(EnumSet.class);
181+
ctxt.reportMappingException(EnumSet.class);
182+
return null;
181183
}
182184

183185
EnumSet result = constructSet();
184186
// First: since `null`s not allowed, slightly simpler...
185187
if (p.hasToken(JsonToken.VALUE_NULL)) {
186-
throw ctxt.mappingException(_enumClass);
188+
ctxt.reportMappingException(_enumClass);
189+
return null;
187190
}
188191
try {
189192
Enum<?> value = _enumDeserializer.deserialize(p, ctxt);

src/main/java/com/fasterxml/jackson/databind/deser/std/FromStringDeserializer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ public T deserialize(JsonParser p, DeserializationContext ctxt) throws IOExcepti
152152
}
153153
return _deserializeEmbedded(ob, ctxt);
154154
}
155-
throw ctxt.mappingException(_valueClass);
155+
ctxt.reportMappingException(_valueClass);
156+
return null;
156157
}
157158

158159
protected abstract T _deserialize(String value, DeserializationContext ctxt) throws IOException;

src/main/java/com/fasterxml/jackson/databind/deser/std/JsonNodeDeserializer.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ public ObjectNode deserialize(JsonParser p, DeserializationContext ctxt) throws
102102
if (p.hasToken(JsonToken.END_OBJECT)) {
103103
return ctxt.getNodeFactory().objectNode();
104104
}
105-
throw ctxt.mappingException(ObjectNode.class);
105+
ctxt.reportMappingException(ObjectNode.class);
106+
return null;
106107
}
107108
}
108109

@@ -123,7 +124,8 @@ public ArrayNode deserialize(JsonParser p, DeserializationContext ctxt) throws I
123124
if (p.isExpectedStartArrayToken()) {
124125
return deserializeArray(p, ctxt, ctxt.getNodeFactory());
125126
}
126-
throw ctxt.mappingException(ArrayNode.class);
127+
ctxt.reportMappingException(ArrayNode.class);
128+
return null;
127129
}
128130
}
129131
}
@@ -332,7 +334,8 @@ protected final JsonNode deserializeAny(JsonParser p, DeserializationContext ctx
332334
//case END_OBJECT:
333335
//case END_ARRAY:
334336
default:
335-
throw ctxt.mappingException(handledType());
337+
ctxt.reportMappingException(handledType());
338+
return null;
336339
}
337340
}
338341

src/main/java/com/fasterxml/jackson/databind/deser/std/MapDeserializer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,8 @@ public Map<Object,Object> deserialize(JsonParser p, DeserializationContext ctxt,
368368
// Ok: must point to START_OBJECT or FIELD_NAME
369369
JsonToken t = p.getCurrentToken();
370370
if (t != JsonToken.START_OBJECT && t != JsonToken.FIELD_NAME) {
371-
throw ctxt.mappingException(getMapClass());
371+
ctxt.reportMappingException(getMapClass());
372+
return null;
372373
}
373374
if (_standardStringKey) {
374375
_readAndBindStringMap(p, ctxt, result);

0 commit comments

Comments
 (0)