1
1
package com .fasterxml .jackson .module .afterburner .ser ;
2
2
3
3
import com .fasterxml .jackson .annotation .JsonInclude ;
4
-
5
4
import com .fasterxml .jackson .databind .ObjectMapper ;
6
-
7
5
import com .fasterxml .jackson .module .afterburner .AfterburnerTestBase ;
8
6
9
7
public class TestInclusionAnnotations extends AfterburnerTestBase
@@ -49,7 +47,7 @@ public class NonEmptyStringWrapper2 {
49
47
public NonEmptyStringWrapper2 (String v ) { value = v ; }
50
48
}
51
49
52
- public class AnyWrapper
50
+ static class AnyWrapper
53
51
{
54
52
public String name = "Foo" ;
55
53
@@ -58,74 +56,70 @@ public class AnyWrapper
58
56
59
57
public AnyWrapper (Object w ) { wrapped = w ; }
60
58
}
61
-
59
+
62
60
/*
63
61
/**********************************************************************
64
62
/* Test methods
65
63
/**********************************************************************
66
64
*/
67
65
66
+ private final ObjectMapper MAPPER = mapperWithModule ();
67
+
68
68
public void testIncludeUsingAnnotation () throws Exception
69
69
{
70
- ObjectMapper mapper = mapperWithModule ();
71
-
72
- String json = mapper .writeValueAsString (new IntWrapper (3 ));
70
+ String json = MAPPER .writeValueAsString (new IntWrapper (3 ));
73
71
assertEquals ("{\" value\" :3}" , json );
74
- json = mapper .writeValueAsString (new IntWrapper (null ));
72
+ json = MAPPER .writeValueAsString (new IntWrapper (null ));
75
73
assertEquals ("{}" , json );
76
74
77
- json = mapper .writeValueAsString (new AnyWrapper (new IntWrapper (null )));
75
+ json = MAPPER .writeValueAsString (new AnyWrapper (new IntWrapper (null )));
78
76
assertEquals ("{\" name\" :\" Foo\" ,\" wrapped\" :{}}" , json );
79
- json = mapper .writeValueAsString (new AnyWrapper (null ));
77
+ json = MAPPER .writeValueAsString (new AnyWrapper (null ));
80
78
assertEquals ("{\" name\" :\" Foo\" }" , json );
81
79
}
82
80
83
81
// [module-afterburner#39]
84
82
public void testEmptyExclusion () throws Exception
85
83
{
86
- ObjectMapper mapper = mapperWithModule ();
87
84
String json ;
88
85
89
- json = mapper .writeValueAsString (new NonEmptyIntWrapper (3 ));
86
+ json = MAPPER .writeValueAsString (new NonEmptyIntWrapper (3 ));
90
87
assertEquals ("{\" value\" :3}" , json );
91
88
// as per [module-afterburner#63], ints should not have "empty" value
92
89
// (temporarily, for 2.6, they did have)
93
- json = mapper .writeValueAsString (new NonEmptyIntWrapper (0 ));
90
+ json = MAPPER .writeValueAsString (new NonEmptyIntWrapper (0 ));
94
91
assertEquals ("{\" value\" :0}" , json );
95
92
96
- json = mapper .writeValueAsString (new NonEmptyStringWrapper ("x" ));
93
+ json = MAPPER .writeValueAsString (new NonEmptyStringWrapper ("x" ));
97
94
assertEquals ("{\" value\" :\" x\" }" , json );
98
- json = mapper .writeValueAsString (new NonEmptyStringWrapper ("" ));
95
+ json = MAPPER .writeValueAsString (new NonEmptyStringWrapper ("" ));
99
96
assertEquals ("{}" , json );
100
- json = mapper .writeValueAsString (new NonEmptyStringWrapper (null ));
97
+ json = MAPPER .writeValueAsString (new NonEmptyStringWrapper (null ));
101
98
assertEquals ("{}" , json );
102
99
}
103
100
104
101
public void testEmptyExclusionViaClass () throws Exception
105
102
{
106
- ObjectMapper mapper = mapperWithModule ();
107
-
108
103
assertEquals ("{\" value\" :3}" ,
109
- mapper .writeValueAsString (new NonEmptyIntWrapper2 (3 )));
104
+ MAPPER .writeValueAsString (new NonEmptyIntWrapper2 (3 )));
110
105
assertEquals ("{\" value\" :0}" ,
111
- mapper .writeValueAsString (new NonEmptyIntWrapper2 (0 )));
106
+ MAPPER .writeValueAsString (new NonEmptyIntWrapper2 (0 )));
112
107
113
108
assertEquals ("{\" value\" :\" x\" }" ,
114
- mapper .writeValueAsString (new NonEmptyStringWrapper2 ("x" )));
109
+ MAPPER .writeValueAsString (new NonEmptyStringWrapper2 ("x" )));
115
110
assertEquals ("{}" ,
116
- mapper .writeValueAsString (new NonEmptyStringWrapper2 ("" )));
111
+ MAPPER .writeValueAsString (new NonEmptyStringWrapper2 ("" )));
117
112
assertEquals ("{}" ,
118
- mapper .writeValueAsString (new NonEmptyStringWrapper2 (null )));
113
+ MAPPER .writeValueAsString (new NonEmptyStringWrapper2 (null )));
119
114
}
120
115
121
116
public void testDefaultExclusion () throws Exception
122
117
{
123
- ObjectMapper mapper = mapperWithModule ();
124
118
String json ;
125
119
126
- json = mapper .writeValueAsString (new NonDefaultIntWrapper (3 ));
120
+ json = MAPPER .writeValueAsString (new NonDefaultIntWrapper (3 ));
127
121
assertEquals ("{\" value\" :3}" , json );
128
- json = mapper .writeValueAsString (new NonDefaultIntWrapper (0 ));
122
+ json = MAPPER .writeValueAsString (new NonDefaultIntWrapper (0 ));
129
123
assertEquals ("{}" , json );
130
124
}
131
125
}
0 commit comments