|
1 | 1 | package com.fasterxml.jackson.databind.exc;
|
2 | 2 |
|
3 | 3 | import java.io.StringWriter;
|
| 4 | +import java.util.ArrayList; |
4 | 5 | import java.util.Collection;
|
5 | 6 | import java.util.Collections;
|
6 |
| -import java.util.Map; |
7 | 7 |
|
8 | 8 | import com.fasterxml.jackson.core.*;
|
9 |
| -import com.fasterxml.jackson.core.type.TypeReference; |
10 | 9 | import com.fasterxml.jackson.databind.*;
|
11 | 10 | import com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition;
|
12 | 11 | import com.fasterxml.jackson.databind.type.TypeFactory;
|
13 | 12 |
|
14 | 13 | public class BasicExceptionTest extends BaseMapTest
|
15 | 14 | {
|
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(); |
18 | 17 |
|
19 | 18 | public void testBadDefinition() throws Exception
|
20 | 19 | {
|
@@ -114,18 +113,31 @@ public void testUnrecognizedProperty() throws Exception
|
114 | 113 | }
|
115 | 114 |
|
116 | 115 | // [databind#2128]: ensure Location added once and only once
|
| 116 | + // [databind#2482]: ensure Location is the original one |
117 | 117 | public void testLocationAddition() throws Exception
|
118 | 118 | {
|
| 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}"; |
119 | 120 | try {
|
120 |
| - /*Map<?,?> map =*/ MAPPER.readValue("{\"value\":\"foo\"}", |
121 |
| - new TypeReference<Map<ABC, Integer>>() { }); |
| 121 | + MAPPER.readValue(problemJson, Users.class); |
122 | 122 | fail("Should not pass");
|
123 |
| - } catch (MismatchedInputException e) { |
| 123 | + } catch (JsonMappingException e) { // becomes "generic" due to wrapping for passing path info |
124 | 124 | String msg = e.getMessage();
|
125 | 125 | String[] str = msg.split(" at \\[");
|
126 | 126 | if (str.length != 2) {
|
127 | 127 | fail("Should only get one 'at [' marker, got "+(str.length-1)+", source: "+msg);
|
128 | 128 | }
|
| 129 | + JsonLocation loc = e.getLocation(); |
| 130 | +// String expectedLocation = "line: 4, column: 4"; |
| 131 | + assertEquals(4, loc.getLineNr()); |
| 132 | + assertEquals(4, loc.getColumnNr()); |
129 | 133 | }
|
130 | 134 | }
|
| 135 | + |
| 136 | + static class User { |
| 137 | + public String user; |
| 138 | + } |
| 139 | + |
| 140 | + static class Users { |
| 141 | + public ArrayList<User> userList; |
| 142 | + } |
131 | 143 | }
|
0 commit comments