Skip to content

Commit 566b607

Browse files
istudenscowtowncoder
authored andcommitted
a test-case for #2482
1 parent 544cc61 commit 566b607

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

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

+29-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
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;
@@ -114,18 +113,43 @@ 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}";
120+
String expectedLocation = "line: 4, column: 4";
119121
try {
120-
/*Map<?,?> map =*/ MAPPER.readValue("{\"value\":\"foo\"}",
121-
new TypeReference<Map<ABC, Integer>>() { });
122+
MAPPER.readValue(problemJson, Users.class);
122123
fail("Should not pass");
123-
} catch (MismatchedInputException e) {
124+
} catch (JsonMappingException e) {
124125
String msg = e.getMessage();
125126
String[] str = msg.split(" at \\[");
126127
if (str.length != 2) {
127128
fail("Should only get one 'at [' marker, got "+(str.length-1)+", source: "+msg);
128129
}
130+
if (! str[1].contains(expectedLocation)) {
131+
fail("Reported location should be \"" + expectedLocation + "\", but was: " + str[1]);
132+
}
133+
}
134+
}
135+
136+
private static class User {
137+
public String user = null;
138+
}
139+
140+
private static class Users {
141+
private ArrayList<User> users = new ArrayList<User>();
142+
143+
public ArrayList<User> getUser() {
144+
return users;
145+
}
146+
147+
public void addUser(User user) {
148+
this.users.add(user);
149+
}
150+
151+
public void setUserList(ArrayList<User> user) {
152+
this.users = user;
129153
}
130154
}
131155
}

0 commit comments

Comments
 (0)