Skip to content

Commit ae2e6ed

Browse files
committed
Fixes to help with #1484
1 parent b325a9c commit ae2e6ed

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

src/main/java/tools/jackson/databind/deser/bean/BeanDeserializer.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ private final Object _vanillaDeserialize(JsonParser p,
402402
try {
403403
prop.deserializeAndSet(p, ctxt, bean);
404404
} catch (Exception e) {
405-
throw wrapAndThrow(e, bean, p.currentName(), ctxt);
405+
throw wrapAndThrow(e, bean, prop.getName(), ctxt);
406406
}
407407

408408
// Elem #2
@@ -415,7 +415,7 @@ private final Object _vanillaDeserialize(JsonParser p,
415415
try {
416416
prop.deserializeAndSet(p, ctxt, bean);
417417
} catch (Exception e) {
418-
throw wrapAndThrow(e, bean, p.currentName(), ctxt);
418+
throw wrapAndThrow(e, bean, prop.getName(), ctxt);
419419
}
420420
ix = p.nextNameMatch(_propNameMatcher);
421421
}
@@ -442,7 +442,7 @@ private final Object _vanillaDeserializeWithUnknown(JsonParser p,
442442
try {
443443
_propsByIndex[ix].deserializeAndSet(p, ctxt, bean);
444444
} catch (Exception e) {
445-
wrapAndThrow(e, bean, p.currentName(), ctxt);
445+
wrapAndThrow(e, bean, _propsByIndex[ix].getName(), ctxt);
446446
}
447447
continue;
448448
}
@@ -537,7 +537,7 @@ else if (_objectIdReader != null && p.hasTokenId(JsonTokenId.ID_END_OBJECT)) {
537537
try {
538538
_propsByIndex[ix].deserializeAndSet(p, ctxt, bean);
539539
} catch (Exception e) {
540-
throw wrapAndThrow(e, bean, p.currentName(), ctxt);
540+
throw wrapAndThrow(e, bean, _propsByIndex[ix].getName(), ctxt);
541541
}
542542
continue;
543543
}
@@ -846,7 +846,7 @@ protected final Object deserializeWithView(JsonParser p, DeserializationContext
846846
try {
847847
prop.deserializeAndSet(p, ctxt, bean);
848848
} catch (Exception e) {
849-
wrapAndThrow(e, bean, p.currentName(), ctxt);
849+
wrapAndThrow(e, bean, prop.getName(), ctxt);
850850
}
851851
continue;
852852
}

src/test/java/tools/jackson/databind/deser/jdk/CollectionDeserTest.java

+17-7
Original file line numberDiff line numberDiff line change
@@ -266,32 +266,42 @@ public void testIterableWithBeans() throws Exception
266266

267267
// for [databind#506]
268268
@Test
269-
public void testArrayIndexForExceptions() throws Exception
269+
public void testArrayIndexForExceptions1() throws Exception
270270
{
271-
final String OBJECTS_JSON = "[ \"KEY2\", false ]";
272271
try {
273-
MAPPER.readValue(OBJECTS_JSON, Key[].class);
272+
MAPPER.readValue("[ \"KEY2\", false ]", Key[].class);
274273
fail("Should not pass");
275274
} catch (MismatchedInputException e) {
276-
verifyException(e, "Cannot deserialize");
275+
verifyException(e, "Cannot deserialize value of type");
276+
verifyException(e, "from Boolean value");
277277
assertEquals(1, e.getPath().size());
278278
assertEquals(1, e.getPath().get(0).getIndex());
279279
}
280+
}
280281

282+
@Test
283+
public void testArrayIndexForExceptions2() throws Exception
284+
{
281285
try {
282286
MAPPER.readValue("[ \"xyz\", { } ]", String[].class);
283287
fail("Should not pass");
284288
} catch (MismatchedInputException e) {
285-
verifyException(e, "Cannot deserialize");
289+
verifyException(e, "Cannot deserialize value of type");
290+
verifyException(e, "from Object value");
286291
assertEquals(1, e.getPath().size());
287292
assertEquals(1, e.getPath().get(0).getIndex());
288293
}
294+
}
289295

296+
@Test
297+
public void testArrayIndexForExceptions3() throws Exception
298+
{
290299
try {
291-
MAPPER.readValue("{\"keys\":"+OBJECTS_JSON+"}", KeyListBean.class);
300+
MAPPER.readValue("{\"keys\":[ \"KEY2\", false ]}", KeyListBean.class);
292301
fail("Should not pass");
293302
} catch (MismatchedInputException e) {
294-
verifyException(e, "Cannot deserialize");
303+
verifyException(e, "Cannot deserialize value of type");
304+
verifyException(e, "from Boolean value");
295305
assertEquals(2, e.getPath().size());
296306
// Bean has no index, but has name:
297307
assertEquals(-1, e.getPath().get(0).getIndex());

0 commit comments

Comments
 (0)