3
3
import com .fasterxml .jackson .dataformat .xml .XmlMapper ;
4
4
import com .fasterxml .jackson .dataformat .xml .XmlTestBase ;
5
5
6
- public class XsiNil354Test extends XmlTestBase
6
+ public class XsiNilBasicTest extends XmlTestBase
7
7
{
8
8
private final static String XSI_NS_DECL = "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" ;
9
-
9
+
10
10
protected static class DoubleWrapper {
11
11
public Double d ;
12
12
@@ -16,6 +16,13 @@ public DoubleWrapper(Double value) {
16
16
}
17
17
}
18
18
19
+ protected static class DoubleWrapper2 {
20
+ public Double a = 100.0 ; // init to ensure it gets overwritten
21
+ public Double b = 200.0 ;
22
+
23
+ public DoubleWrapper2 () { }
24
+ }
25
+
19
26
private final XmlMapper MAPPER = newMapper ();
20
27
21
28
public void testWithDoubleAsNull () throws Exception
@@ -44,6 +51,40 @@ public void testWithDoubleAsNonNull() throws Exception
44
51
assertEquals (Double .valueOf (0.25 ), bean .d );
45
52
}
46
53
54
+ public void testWithDoubleAsMixed () throws Exception
55
+ {
56
+ DoubleWrapper2 bean = MAPPER .readValue (
57
+ "<DoubleWrapper " +XSI_NS_DECL +">\n "
58
+ +"<a xsi:nil='true'></a>\n "
59
+ +"<b xsi:nil='false'>0.25</b>\n "
60
+ +"</DoubleWrapper>" ,
61
+ DoubleWrapper2 .class );
62
+ assertNotNull (bean );
63
+ assertNull (bean .a );
64
+ assertEquals (Double .valueOf (0.25 ), bean .b );
65
+
66
+ bean = MAPPER .readValue (
67
+ "<DoubleWrapper " +XSI_NS_DECL +">\n "
68
+ +"<a xsi:nil='false'>0.25</a>\n "
69
+ +"<b xsi:nil='true'></b>\n "
70
+ +"</DoubleWrapper>" ,
71
+ DoubleWrapper2 .class );
72
+ assertNotNull (bean );
73
+ assertEquals (Double .valueOf (0.25 ), bean .a );
74
+ assertNull (bean .b );
75
+
76
+ // and last one just for ... funsies
77
+ DoubleWrapper2 defaultValue = new DoubleWrapper2 ();
78
+ bean = MAPPER .readValue (
79
+ "<DoubleWrapper " +XSI_NS_DECL +">\n "
80
+ +"</DoubleWrapper>" ,
81
+ DoubleWrapper2 .class );
82
+ assertNotNull (bean .a );
83
+ assertNotNull (bean .b );
84
+ assertEquals (defaultValue .a , bean .a );
85
+ assertEquals (defaultValue .b , bean .b );
86
+ }
87
+
47
88
public void testRootPojoAsNull () throws Exception
48
89
{
49
90
Point bean = MAPPER .readValue (
0 commit comments