@@ -44,12 +44,14 @@ public void setValue(String v) {
44
44
/**********************************************************
45
45
*/
46
46
47
- private final XmlMapper MAPPER = newMapper ();
47
+ private final XmlMapper NULL_EXPOSING_MAPPER = mapperBuilder ()
48
+ .enable (FromXmlParser .Feature .EMPTY_ELEMENT_AS_NULL )
49
+ .build ();
48
50
49
51
public void testSkipNullField1 () throws Exception
50
52
{
51
53
// first, ok if assigning non-null to not-nullable, null for nullable
52
- NullSkipField result = MAPPER .readValue (
54
+ NullSkipField result = NULL_EXPOSING_MAPPER .readValue (
53
55
//"<NullSkipField><noNulls>foo</noNulls><nullsOk></nullsOk></NullSkipField>",
54
56
"<NullSkipField><noNulls>foo</noNulls><nullsOk /></NullSkipField>" ,
55
57
NullSkipField .class );
@@ -60,15 +62,15 @@ public void testSkipNullField1() throws Exception
60
62
public void testSkipNullField2 () throws Exception
61
63
{
62
64
// and then see that nulls are not ok for non-nullable
63
- NullSkipField result = MAPPER .readValue ("<NullSkipField><noNulls /></NullSkipField>" ,
65
+ NullSkipField result = NULL_EXPOSING_MAPPER .readValue ("<NullSkipField><noNulls /></NullSkipField>" ,
64
66
NullSkipField .class );
65
67
assertEquals ("b" , result .noNulls );
66
68
assertEquals ("a" , result .nullsOk );
67
69
}
68
70
69
71
public void testSkipNullMethod1 () throws Exception
70
72
{
71
- NullSkipMethod result = MAPPER .readValue (
73
+ NullSkipMethod result = NULL_EXPOSING_MAPPER .readValue (
72
74
//"<NullSkipMethod><noNulls>foo<noNulls><nullsOk></nullsOk></NullSkipMethod>",
73
75
"<NullSkipMethod><noNulls>foo</noNulls><nullsOk /></NullSkipMethod>" ,
74
76
NullSkipMethod .class );
@@ -78,7 +80,7 @@ public void testSkipNullMethod1() throws Exception
78
80
79
81
public void testSkipNullMethod2 () throws Exception
80
82
{
81
- NullSkipMethod result = MAPPER .readValue ("<NullSkipMethod><noNulls /></NullSkipMethod>" ,
83
+ NullSkipMethod result = NULL_EXPOSING_MAPPER .readValue ("<NullSkipMethod><noNulls /></NullSkipMethod>" ,
82
84
NullSkipMethod .class );
83
85
assertEquals ("b" , result ._noNulls );
84
86
assertEquals ("a" , result ._nullsOk );
@@ -94,10 +96,12 @@ public void testSkipNullWithDefaults() throws Exception
94
96
{
95
97
// String doc = "<StringValue><value></value></StringValue>";
96
98
String doc = "<StringValue><value /></StringValue>" ;
97
- StringValue result = MAPPER .readValue (doc , StringValue .class );
99
+ StringValue result = NULL_EXPOSING_MAPPER .readValue (doc , StringValue .class );
98
100
assertNull (result .value );
99
101
100
- ObjectMapper mapper = newMapper ();
102
+ ObjectMapper mapper = mapperBuilder ()
103
+ .enable (FromXmlParser .Feature .EMPTY_ELEMENT_AS_NULL )
104
+ .build ();
101
105
mapper .configOverride (String .class )
102
106
.setSetterInfo (JsonSetter .Value .forValueNulls (Nulls .SKIP ));
103
107
result = mapper .readValue (doc , StringValue .class );
0 commit comments