|
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;
|
@@ -114,18 +113,43 @@ 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}"; |
| 120 | + String expectedLocation = "line: 4, column: 4"; |
119 | 121 | try {
|
120 |
| - /*Map<?,?> map =*/ MAPPER.readValue("{\"value\":\"foo\"}", |
121 |
| - new TypeReference<Map<ABC, Integer>>() { }); |
| 122 | + MAPPER.readValue(problemJson, Users.class); |
122 | 123 | fail("Should not pass");
|
123 |
| - } catch (MismatchedInputException e) { |
| 124 | + } catch (JsonMappingException e) { |
124 | 125 | String msg = e.getMessage();
|
125 | 126 | String[] str = msg.split(" at \\[");
|
126 | 127 | if (str.length != 2) {
|
127 | 128 | fail("Should only get one 'at [' marker, got "+(str.length-1)+", source: "+msg);
|
128 | 129 | }
|
| 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; |
129 | 153 | }
|
130 | 154 | }
|
131 | 155 | }
|
0 commit comments