1 package com.fasterxml.jackson.databind.exc; 2 3 import com.fasterxml.jackson.databind.BaseMapTest; 4 import com.fasterxml.jackson.databind.JsonMappingException; 5 import com.fasterxml.jackson.databind.ObjectMapper; 6 7 import java.io.IOException; 8 9 public class TestExceptionHandlingWithDefaultDeserialization extends BaseMapTest 10 { 11 static class Foo { 12 private Bar bar; 13 Foo()14 public Foo() { } 15 getBar()16 public Bar getBar() { 17 return bar; 18 } 19 } 20 21 static class Bar { 22 private Baz baz; 23 Bar()24 public Bar() { } 25 getBaz()26 public Baz getBaz() { 27 return baz; 28 } 29 } 30 31 static class Baz { 32 private String qux; 33 Baz()34 public Baz() { } 35 getQux()36 public String getQux() { 37 return qux; 38 } 39 } 40 testShouldThrowJsonMappingExceptionWithPathReference()41 public void testShouldThrowJsonMappingExceptionWithPathReference() throws IOException { 42 // given 43 ObjectMapper mapper = new ObjectMapper(); 44 String input = "{\"bar\":{\"baz\":{qux:\"quxValue\"))}"; 45 final String THIS = getClass().getName(); 46 47 // when 48 try { 49 mapper.readValue(input, Foo.class); 50 fail("Upsss! Exception has not been thrown."); 51 } catch (JsonMappingException ex) { 52 // then 53 assertEquals(THIS+"$Foo[\"bar\"]->"+THIS+"$Bar[\"baz\"]", 54 ex.getPathReference()); 55 } 56 } 57 } 58