Skip to content

Commit f00c1cd

Browse files
committed
Fix #2473
1 parent ca1867e commit f00c1cd

File tree

3 files changed

+39
-23
lines changed

3 files changed

+39
-23
lines changed

release-notes/CREDITS-2.x

+6-1
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,12 @@ Andrey Kulikov (ankulikov@github)
976976
* Reported #2457: Extended enum values are not handled as enums when used as Map keys
977977
(2.10.1)
978978
979+
João Guerra (joca-bt@github)
980+
* Reported #2473: Array index missing in path of `JsonMappingException` for `Collection<String>`,
981+
with custom deserializer
982+
(2.10.1)
983+
979984
Ryan Bohn (bohnman@github)
980-
* Reported `StringCollectionSerializer` calls `JsonGenerator.setCurrentValue(value)`,
985+
* Reported #2475: `StringCollectionSerializer` calls `JsonGenerator.setCurrentValue(value)`,
981986
which messes up current value for sibling properties
982987
(2.10.1)

release-notes/VERSION-2.x

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ Project: jackson-databind
88

99
#2457: Extended enum values are not handled as enums when used as Map keys
1010
(reported by Andrey K)
11+
#2473: Array index missing in path of `JsonMappingException` for `Collection<String>`,
12+
with custom deserializer
13+
(reported by João G)
1114
#2475: `StringCollectionSerializer` calls `JsonGenerator.setCurrentValue(value)`,
1215
which messes up current value for sibling properties
1316
(reported by Ryan B)

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

+30-22
Original file line numberDiff line numberDiff line change
@@ -217,35 +217,39 @@ public Collection<String> deserialize(JsonParser p, DeserializationContext ctxt,
217217
private Collection<String> deserializeUsingCustom(JsonParser p, DeserializationContext ctxt,
218218
Collection<String> result, final JsonDeserializer<String> deser) throws IOException
219219
{
220-
while (true) {
221-
/* 30-Dec-2014, tatu: This may look odd, but let's actually call method
222-
* that suggest we are expecting a String; this helps with some formats,
223-
* notably XML. Note, however, that while we can get String, we can't
224-
* assume that's what we use due to custom deserializer
225-
*/
226-
String value;
227-
if (p.nextTextValue() == null) {
228-
JsonToken t = p.getCurrentToken();
229-
if (t == JsonToken.END_ARRAY) {
230-
break;
231-
}
232-
// Ok: no need to convert Strings, but must recognize nulls
233-
if (t == JsonToken.VALUE_NULL) {
234-
if (_skipNullValues) {
235-
continue;
220+
try {
221+
while (true) {
222+
/* 30-Dec-2014, tatu: This may look odd, but let's actually call method
223+
* that suggest we are expecting a String; this helps with some formats,
224+
* notably XML. Note, however, that while we can get String, we can't
225+
* assume that's what we use due to custom deserializer
226+
*/
227+
String value;
228+
if (p.nextTextValue() == null) {
229+
JsonToken t = p.getCurrentToken();
230+
if (t == JsonToken.END_ARRAY) {
231+
break;
232+
}
233+
// Ok: no need to convert Strings, but must recognize nulls
234+
if (t == JsonToken.VALUE_NULL) {
235+
if (_skipNullValues) {
236+
continue;
237+
}
238+
value = (String) _nullProvider.getNullValue(ctxt);
239+
} else {
240+
value = deser.deserialize(p, ctxt);
236241
}
237-
value = (String) _nullProvider.getNullValue(ctxt);
238242
} else {
239243
value = deser.deserialize(p, ctxt);
240244
}
241-
} else {
242-
value = deser.deserialize(p, ctxt);
245+
result.add(value);
243246
}
244-
result.add(value);
247+
} catch (Exception e) {
248+
throw JsonMappingException.wrapWithPath(e, result, result.size());
245249
}
246250
return result;
247251
}
248-
252+
249253
@Override
250254
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt,
251255
TypeDeserializer typeDeserializer) throws IOException {
@@ -282,7 +286,11 @@ private final Collection<String> handleNonArray(JsonParser p, DeserializationCon
282286
}
283287
value = (String) _nullProvider.getNullValue(ctxt);
284288
} else {
285-
value = (valueDes == null) ? _parseString(p, ctxt) : valueDes.deserialize(p, ctxt);
289+
try {
290+
value = (valueDes == null) ? _parseString(p, ctxt) : valueDes.deserialize(p, ctxt);
291+
} catch (Exception e) {
292+
throw JsonMappingException.wrapWithPath(e, result, result.size());
293+
}
286294
}
287295
result.add(value);
288296
return result;

0 commit comments

Comments
 (0)