Skip to content

Commit

Permalink
a test-case for FasterXML#2482
Browse files Browse the repository at this point in the history
  • Loading branch information
istudens committed Feb 4, 2020
1 parent aef9cdf commit b6e5a68
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ public JsonMappingException(Closeable processor, String msg) {
public JsonMappingException(Closeable processor, String msg, Throwable problem) {
super(msg, problem);
_processor = processor;
// 31-Jan-2020: [databind#2482] Retain original location
if (problem instanceof JsonProcessingException) {
_location = ((JsonProcessingException) problem).getLocation();
} else if (processor instanceof JsonParser) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package com.fasterxml.jackson.databind.exc;

import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;

import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition;
import com.fasterxml.jackson.databind.type.TypeFactory;

public class BasicExceptionTest extends BaseMapTest
{
final ObjectMapper MAPPER = new ObjectMapper();
final JsonFactory JSON_F = MAPPER.getFactory();
private final ObjectMapper MAPPER = new ObjectMapper();
private final JsonFactory JSON_F = MAPPER.getFactory();

public void testBadDefinition() throws Exception
{
Expand Down Expand Up @@ -114,18 +113,31 @@ public void testUnrecognizedProperty() throws Exception
}

// [databind#2128]: ensure Location added once and only once
// [databind#2482]: ensure Location is the original one
public void testLocationAddition() throws Exception
{
String problemJson = "{\n\t\"userList\" : [\n\t{\n\t user : \"1\"\n\t},\n\t{\n\t \"user\" : \"2\"\n\t}\n\t]\n}";
try {
/*Map<?,?> map =*/ MAPPER.readValue("{\"value\":\"foo\"}",
new TypeReference<Map<ABC, Integer>>() { });
MAPPER.readValue(problemJson, Users.class);
fail("Should not pass");
} catch (MismatchedInputException e) {
} catch (JsonMappingException e) { // becomes "generic" due to wrapping for passing path info
String msg = e.getMessage();
String[] str = msg.split(" at \\[");
if (str.length != 2) {
fail("Should only get one 'at [' marker, got "+(str.length-1)+", source: "+msg);
}
JsonLocation loc = e.getLocation();
// String expectedLocation = "line: 4, column: 4";
assertEquals(4, loc.getLineNr());
assertEquals(4, loc.getColumnNr());
}
}

static class User {
public String user;
}

static class Users {
public ArrayList<User> userList;
}
}

0 comments on commit b6e5a68

Please sign in to comment.