From 566b607827c5dd004fdaca992c12b3e1ac0d30e6 Mon Sep 17 00:00:00 2001 From: Ivo Studensky Date: Fri, 31 Jan 2020 21:43:10 +0100 Subject: [PATCH] a test-case for #2482 --- .../databind/exc/BasicExceptionTest.java | 34 ++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/test/java/com/fasterxml/jackson/databind/exc/BasicExceptionTest.java b/src/test/java/com/fasterxml/jackson/databind/exc/BasicExceptionTest.java index 3c4d2bb357..e13979492a 100644 --- a/src/test/java/com/fasterxml/jackson/databind/exc/BasicExceptionTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/exc/BasicExceptionTest.java @@ -1,12 +1,11 @@ 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; @@ -114,18 +113,43 @@ 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}"; + String expectedLocation = "line: 4, column: 4"; try { - /*Map map =*/ MAPPER.readValue("{\"value\":\"foo\"}", - new TypeReference>() { }); + MAPPER.readValue(problemJson, Users.class); fail("Should not pass"); - } catch (MismatchedInputException e) { + } catch (JsonMappingException e) { 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); } + if (! str[1].contains(expectedLocation)) { + fail("Reported location should be \"" + expectedLocation + "\", but was: " + str[1]); + } + } + } + + private static class User { + public String user = null; + } + + private static class Users { + private ArrayList users = new ArrayList(); + + public ArrayList getUser() { + return users; + } + + public void addUser(User user) { + this.users.add(user); + } + + public void setUserList(ArrayList user) { + this.users = user; } } }