44import java .util .List ;
55
66import com .fasterxml .jackson .annotation .*;
7+
78import com .fasterxml .jackson .databind .*;
89import com .fasterxml .jackson .databind .module .SimpleModule ;
910
@@ -58,32 +59,47 @@ static class Wrapped {
5859 public Wrapped (int x0 ) { x = x0 ; }
5960 }
6061
62+ // [databind#2893]
63+ @ JsonIgnoreType
64+ interface IgnoreMe { }
65+
66+ static class ChildOfIgnorable implements IgnoreMe {
67+ public int value = 42 ;
68+ }
69+
70+ static class ContainsIgnorable {
71+ public ChildOfIgnorable ign = new ChildOfIgnorable ();
72+
73+ public int x = 13 ;
74+ }
75+
6176 /*
6277 /**********************************************************
6378 /* Unit tests
6479 /**********************************************************
6580 */
66-
81+
82+ private final ObjectMapper MAPPER = newJsonMapper ();
83+
6784 public void testIgnoredType () throws Exception
6885 {
69- final ObjectMapper mapper = objectMapper ();
70-
7186 // First: should be ok in general, even though couldn't build deserializer (due to non-static inner class):
72- NonIgnoredType bean = mapper .readValue ("{\" value\" :13}" , NonIgnoredType .class );
87+ NonIgnoredType bean = MAPPER .readValue ("{\" value\" :13}" , NonIgnoredType .class );
7388 assertNotNull (bean );
7489 assertEquals (13 , bean .value );
7590
7691 // And also ok to see something with that value; will just get ignored
77- bean = mapper .readValue ("{ \" ignored\" :[1,2,{}], \" value\" :9 }" , NonIgnoredType .class );
92+ bean = MAPPER .readValue ("{ \" ignored\" :[1,2,{}], \" value\" :9 }" , NonIgnoredType .class );
7893 assertNotNull (bean );
7994 assertEquals (9 , bean .value );
8095 }
8196
8297 public void testSingleWithMixins () throws Exception {
8398 SimpleModule module = new SimpleModule ();
8499 module .setMixInAnnotation (Person .class , PersonMixin .class );
85- ObjectMapper mapper = new ObjectMapper ();
86- mapper .registerModule (module );
100+ ObjectMapper mapper = jsonMapperBuilder ()
101+ .addModule (module )
102+ .build ();
87103 PersonWrapper input = new PersonWrapper ();
88104 String json = mapper .writeValueAsString (input );
89105 assertEquals ("{\" value\" :1}" , json );
@@ -92,8 +108,9 @@ public void testSingleWithMixins() throws Exception {
92108 public void testListWithMixins () throws Exception {
93109 SimpleModule module = new SimpleModule ();
94110 module .setMixInAnnotation (Person .class , PersonMixin .class );
95- ObjectMapper mapper = new ObjectMapper ();
96- mapper .registerModule (module );
111+ ObjectMapper mapper = jsonMapperBuilder ()
112+ .addModule (module )
113+ .build ();
97114 List <Person > persons = new ArrayList <Person >();
98115 persons .add (new Person ("Bob" ));
99116 String json = mapper .writeValueAsString (persons );
@@ -102,7 +119,7 @@ public void testListWithMixins() throws Exception {
102119
103120 public void testIgnoreUsingConfigOverride () throws Exception
104121 {
105- final ObjectMapper mapper = objectMapper ();
122+ final ObjectMapper mapper = newJsonMapper ();
106123 mapper .configOverride (Wrapped .class ).setIsIgnoredType (true );
107124
108125 // serialize , first
@@ -114,4 +131,10 @@ public void testIgnoreUsingConfigOverride() throws Exception
114131 Wrapper .class );
115132 assertEquals (5 , result .value );
116133 }
134+
135+ // [databind#2893]
136+ public void testIgnoreTypeViaInterface () throws Exception
137+ {
138+ assertEquals (a2q ("{'x':13}" ), MAPPER .writeValueAsString (new ContainsIgnorable ()));
139+ }
117140}
0 commit comments