Skip to content

Commit

Permalink
Fixes to help with #1484
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jan 31, 2025
1 parent b325a9c commit ae2e6ed
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ private final Object _vanillaDeserialize(JsonParser p,
try {
prop.deserializeAndSet(p, ctxt, bean);
} catch (Exception e) {
throw wrapAndThrow(e, bean, p.currentName(), ctxt);
throw wrapAndThrow(e, bean, prop.getName(), ctxt);
}

// Elem #2
Expand All @@ -415,7 +415,7 @@ private final Object _vanillaDeserialize(JsonParser p,
try {
prop.deserializeAndSet(p, ctxt, bean);
} catch (Exception e) {
throw wrapAndThrow(e, bean, p.currentName(), ctxt);
throw wrapAndThrow(e, bean, prop.getName(), ctxt);
}
ix = p.nextNameMatch(_propNameMatcher);
}
Expand All @@ -442,7 +442,7 @@ private final Object _vanillaDeserializeWithUnknown(JsonParser p,
try {
_propsByIndex[ix].deserializeAndSet(p, ctxt, bean);
} catch (Exception e) {
wrapAndThrow(e, bean, p.currentName(), ctxt);
wrapAndThrow(e, bean, _propsByIndex[ix].getName(), ctxt);
}
continue;
}
Expand Down Expand Up @@ -537,7 +537,7 @@ else if (_objectIdReader != null && p.hasTokenId(JsonTokenId.ID_END_OBJECT)) {
try {
_propsByIndex[ix].deserializeAndSet(p, ctxt, bean);
} catch (Exception e) {
throw wrapAndThrow(e, bean, p.currentName(), ctxt);
throw wrapAndThrow(e, bean, _propsByIndex[ix].getName(), ctxt);
}
continue;
}
Expand Down Expand Up @@ -846,7 +846,7 @@ protected final Object deserializeWithView(JsonParser p, DeserializationContext
try {
prop.deserializeAndSet(p, ctxt, bean);
} catch (Exception e) {
wrapAndThrow(e, bean, p.currentName(), ctxt);
wrapAndThrow(e, bean, prop.getName(), ctxt);
}
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,32 +266,42 @@ public void testIterableWithBeans() throws Exception

// for [databind#506]
@Test
public void testArrayIndexForExceptions() throws Exception
public void testArrayIndexForExceptions1() throws Exception
{
final String OBJECTS_JSON = "[ \"KEY2\", false ]";
try {
MAPPER.readValue(OBJECTS_JSON, Key[].class);
MAPPER.readValue("[ \"KEY2\", false ]", Key[].class);
fail("Should not pass");
} catch (MismatchedInputException e) {
verifyException(e, "Cannot deserialize");
verifyException(e, "Cannot deserialize value of type");
verifyException(e, "from Boolean value");
assertEquals(1, e.getPath().size());
assertEquals(1, e.getPath().get(0).getIndex());
}
}

@Test
public void testArrayIndexForExceptions2() throws Exception
{
try {
MAPPER.readValue("[ \"xyz\", { } ]", String[].class);
fail("Should not pass");
} catch (MismatchedInputException e) {
verifyException(e, "Cannot deserialize");
verifyException(e, "Cannot deserialize value of type");
verifyException(e, "from Object value");
assertEquals(1, e.getPath().size());
assertEquals(1, e.getPath().get(0).getIndex());
}
}

@Test
public void testArrayIndexForExceptions3() throws Exception
{
try {
MAPPER.readValue("{\"keys\":"+OBJECTS_JSON+"}", KeyListBean.class);
MAPPER.readValue("{\"keys\":[ \"KEY2\", false ]}", KeyListBean.class);
fail("Should not pass");
} catch (MismatchedInputException e) {
verifyException(e, "Cannot deserialize");
verifyException(e, "Cannot deserialize value of type");
verifyException(e, "from Boolean value");
assertEquals(2, e.getPath().size());
// Bean has no index, but has name:
assertEquals(-1, e.getPath().get(0).getIndex());
Expand Down

0 comments on commit ae2e6ed

Please sign in to comment.