Skip to content

Commit 8b6cabf

Browse files
committed
Merge branch '2.10' into 2.11
2 parents 93e46c4 + effe1c3 commit 8b6cabf

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

release-notes/CREDITS-2.x

+8
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,9 @@ Ivo Studens ([email protected])
611611
* Contributed #1585: Invoke ServiceLoader.load() inside of a privileged block
612612
when loading modules using `ObjectMapper.findModules()`
613613
(2.8.9)
614+
* Contributed fix for #2482: `JSONMappingException` `Location` column number
615+
is one line Behind the actual location
616+
(2.10.3)
614617

615618
Javy Luo (AnywnYu@github)
616619
* Reported #1595: `JsonIgnoreProperties.allowSetters` is not working in Jackson 2.8
@@ -1023,6 +1026,11 @@ Greg Arakelian (arakelian@github)
10231026
of empty string
10241027
(2.10.2)
10251028
1029+
Kamal Aslam (aslamkam@github)
1030+
* Reported #2482: `JSONMappingException` `Location` column number is one line
1031+
Behind the actual location
1032+
(2.10.3)
1033+
10261034
Tobias Preuss (johnjohndoe@github)
10271035
* Reported #2599: NoClassDefFoundError at DeserializationContext.<init> on Android 4.1.2
10281036
and Jackson 2.10.0

release-notes/VERSION-2.x

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

4242
2.10.3 (not yet released)
4343

44+
#2482: `JSONMappingException` `Location` column number is one line Behind the actual
45+
location
46+
(reported by Kamal A, fixed by Ivo S)
4447
#2599: NoClassDefFoundError at DeserializationContext.<init> on Android 4.1.2
4548
and Jackson 2.10.0
4649
(reported by Tobias P)

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

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

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

+18-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 = newJsonMapper();
16+
private final JsonFactory JSON_F = MAPPER.getFactory();
1817

1918
public void testBadDefinition() throws Exception
2019
{
@@ -114,18 +113,30 @@ 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+
static class User {
136+
public String user;
137+
}
138+
139+
static class Users {
140+
public ArrayList<User> userList;
141+
}
131142
}

0 commit comments

Comments
 (0)