4
4
import java .util .List ;
5
5
6
6
import com .fasterxml .jackson .annotation .*;
7
+
7
8
import com .fasterxml .jackson .databind .*;
8
9
import com .fasterxml .jackson .databind .module .SimpleModule ;
9
10
@@ -58,32 +59,47 @@ static class Wrapped {
58
59
public Wrapped (int x0 ) { x = x0 ; }
59
60
}
60
61
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
+
61
76
/*
62
77
/**********************************************************
63
78
/* Unit tests
64
79
/**********************************************************
65
80
*/
66
-
81
+
82
+ private final ObjectMapper MAPPER = newJsonMapper ();
83
+
67
84
public void testIgnoredType () throws Exception
68
85
{
69
- final ObjectMapper mapper = objectMapper ();
70
-
71
86
// 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 );
73
88
assertNotNull (bean );
74
89
assertEquals (13 , bean .value );
75
90
76
91
// 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 );
78
93
assertNotNull (bean );
79
94
assertEquals (9 , bean .value );
80
95
}
81
96
82
97
public void testSingleWithMixins () throws Exception {
83
98
SimpleModule module = new SimpleModule ();
84
99
module .setMixInAnnotation (Person .class , PersonMixin .class );
85
- ObjectMapper mapper = new ObjectMapper ();
86
- mapper .registerModule (module );
100
+ ObjectMapper mapper = jsonMapperBuilder ()
101
+ .addModule (module )
102
+ .build ();
87
103
PersonWrapper input = new PersonWrapper ();
88
104
String json = mapper .writeValueAsString (input );
89
105
assertEquals ("{\" value\" :1}" , json );
@@ -92,8 +108,9 @@ public void testSingleWithMixins() throws Exception {
92
108
public void testListWithMixins () throws Exception {
93
109
SimpleModule module = new SimpleModule ();
94
110
module .setMixInAnnotation (Person .class , PersonMixin .class );
95
- ObjectMapper mapper = new ObjectMapper ();
96
- mapper .registerModule (module );
111
+ ObjectMapper mapper = jsonMapperBuilder ()
112
+ .addModule (module )
113
+ .build ();
97
114
List <Person > persons = new ArrayList <Person >();
98
115
persons .add (new Person ("Bob" ));
99
116
String json = mapper .writeValueAsString (persons );
@@ -102,7 +119,7 @@ public void testListWithMixins() throws Exception {
102
119
103
120
public void testIgnoreUsingConfigOverride () throws Exception
104
121
{
105
- final ObjectMapper mapper = objectMapper ();
122
+ final ObjectMapper mapper = newJsonMapper ();
106
123
mapper .configOverride (Wrapped .class ).setIsIgnoredType (true );
107
124
108
125
// serialize , first
@@ -114,4 +131,10 @@ public void testIgnoreUsingConfigOverride() throws Exception
114
131
Wrapper .class );
115
132
assertEquals (5 , result .value );
116
133
}
134
+
135
+ // [databind#2893]
136
+ public void testIgnoreTypeViaInterface () throws Exception
137
+ {
138
+ assertEquals (a2q ("{'x':13}" ), MAPPER .writeValueAsString (new ContainsIgnorable ()));
139
+ }
117
140
}
0 commit comments