Skip to content

Commit b6e5a68

Browse files
committed
a test-case for FasterXML#2482
1 parent aef9cdf commit b6e5a68

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ public JsonMappingException(Closeable processor, String msg) {
251251
public JsonMappingException(Closeable processor, String msg, Throwable problem) {
252252
super(msg, problem);
253253
_processor = processor;
254+
// 31-Jan-2020: [databind#2482] Retain original location
254255
if (problem instanceof JsonProcessingException) {
255256
_location = ((JsonProcessingException) problem).getLocation();
256257
} else if (processor instanceof JsonParser) {

src/test/java/com/fasterxml/jackson/databind/exc/BasicExceptionTest.java

+19-7
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
package com.fasterxml.jackson.databind.exc;
22

33
import java.io.StringWriter;
4+
import java.util.ArrayList;
45
import java.util.Collection;
56
import java.util.Collections;
6-
import java.util.Map;
77

88
import com.fasterxml.jackson.core.*;
9-
import com.fasterxml.jackson.core.type.TypeReference;
109
import com.fasterxml.jackson.databind.*;
1110
import com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition;
1211
import com.fasterxml.jackson.databind.type.TypeFactory;
1312

1413
public class BasicExceptionTest extends BaseMapTest
1514
{
16-
final ObjectMapper MAPPER = new ObjectMapper();
17-
final JsonFactory JSON_F = MAPPER.getFactory();
15+
private final ObjectMapper MAPPER = new ObjectMapper();
16+
private final JsonFactory JSON_F = MAPPER.getFactory();
1817

1918
public void testBadDefinition() throws Exception
2019
{
@@ -114,18 +113,31 @@ public void testUnrecognizedProperty() throws Exception
114113
}
115114

116115
// [databind#2128]: ensure Location added once and only once
116+
// [databind#2482]: ensure Location is the original one
117117
public void testLocationAddition() throws Exception
118118
{
119+
String problemJson = "{\n\t\"userList\" : [\n\t{\n\t user : \"1\"\n\t},\n\t{\n\t \"user\" : \"2\"\n\t}\n\t]\n}";
119120
try {
120-
/*Map<?,?> map =*/ MAPPER.readValue("{\"value\":\"foo\"}",
121-
new TypeReference<Map<ABC, Integer>>() { });
121+
MAPPER.readValue(problemJson, Users.class);
122122
fail("Should not pass");
123-
} catch (MismatchedInputException e) {
123+
} catch (JsonMappingException e) { // becomes "generic" due to wrapping for passing path info
124124
String msg = e.getMessage();
125125
String[] str = msg.split(" at \\[");
126126
if (str.length != 2) {
127127
fail("Should only get one 'at [' marker, got "+(str.length-1)+", source: "+msg);
128128
}
129+
JsonLocation loc = e.getLocation();
130+
// String expectedLocation = "line: 4, column: 4";
131+
assertEquals(4, loc.getLineNr());
132+
assertEquals(4, loc.getColumnNr());
129133
}
130134
}
135+
136+
static class User {
137+
public String user;
138+
}
139+
140+
static class Users {
141+
public ArrayList<User> userList;
142+
}
131143
}

0 commit comments

Comments
 (0)