@@ -29,6 +29,15 @@ public OptionalNonEmptyStringBean() { }
29
29
}
30
30
}
31
31
32
+ public static final class OptionalGenericData <T > {
33
+ public Optional <T > myData ;
34
+ public static <T > OptionalGenericData <T > construct (T data ) {
35
+ OptionalGenericData <T > ret = new OptionalGenericData <T >();
36
+ ret .myData = Optional .of (data );
37
+ return ret ;
38
+ }
39
+ }
40
+
32
41
private final ObjectMapper MAPPER = mapperWithModule ();
33
42
34
43
public void testSerOptNonEmpty () throws Exception
@@ -58,4 +67,40 @@ public void testExcludeEmptyStringViaOptional() throws Exception
58
67
json = MAPPER .writeValueAsString (new OptionalNonEmptyStringBean ("" ));
59
68
assertEquals ("{}" , json );
60
69
}
70
+
71
+ public void testSerPropInclusionAlways () throws Exception
72
+ {
73
+ JsonInclude .Value incl =
74
+ JsonInclude .Value .construct (JsonInclude .Include .NON_ABSENT , JsonInclude .Include .ALWAYS );
75
+ ObjectMapper mapper = mapperWithModule ().setPropertyInclusion (incl );
76
+ assertEquals ("{\" myData\" :true}" ,
77
+ mapper .writeValueAsString (OptionalGenericData .construct (Boolean .TRUE )));
78
+ }
79
+
80
+ public void testSerPropInclusionNonNull () throws Exception
81
+ {
82
+ JsonInclude .Value incl =
83
+ JsonInclude .Value .construct (JsonInclude .Include .NON_ABSENT , JsonInclude .Include .NON_NULL );
84
+ ObjectMapper mapper = mapperWithModule ().setPropertyInclusion (incl );
85
+ assertEquals ("{\" myData\" :true}" ,
86
+ mapper .writeValueAsString (OptionalGenericData .construct (Boolean .TRUE )));
87
+ }
88
+
89
+ public void testSerPropInclusionNonAbsent () throws Exception
90
+ {
91
+ JsonInclude .Value incl =
92
+ JsonInclude .Value .construct (JsonInclude .Include .NON_ABSENT , JsonInclude .Include .NON_ABSENT );
93
+ ObjectMapper mapper = mapperWithModule ().setPropertyInclusion (incl );
94
+ assertEquals ("{\" myData\" :true}" ,
95
+ mapper .writeValueAsString (OptionalGenericData .construct (Boolean .TRUE )));
96
+ }
97
+
98
+ public void testSerPropInclusionNonEmpty () throws Exception
99
+ {
100
+ JsonInclude .Value incl =
101
+ JsonInclude .Value .construct (JsonInclude .Include .NON_ABSENT , JsonInclude .Include .NON_EMPTY );
102
+ ObjectMapper mapper = mapperWithModule ().setPropertyInclusion (incl );
103
+ assertEquals ("{\" myData\" :true}" ,
104
+ mapper .writeValueAsString (OptionalGenericData .construct (Boolean .TRUE )));
105
+ }
61
106
}
0 commit comments