@@ -14,26 +14,33 @@ public DoubleWrapper(Double value) {
1414 }
1515 }
1616
17- protected static class Parent {
18- public Level1 level1 ;
19- }
20-
21- protected static class Level1 {
22- public Level2 level2 ;
23- public String field ; // this should not be needed, but an unknown element is thrown without it
24- }
25-
26- protected static class Level2 {
27- public String ignored ;
28- public String field ;
29- }
30-
3117 private final XmlMapper MAPPER = newMapper ();
3218
3319 public void testWithDoubleAsNull () throws Exception
3420 {
3521 DoubleWrapper bean = MAPPER .readValue (
36- "<DoubleWrapper xmlns:xsi=\" http://www.w3.org/2001/XMLSchema-instance\" ><d xsi:nil='true' /></DoubleWrapper>" ,
22+ "<DoubleWrapper xmlns:xsi=\" http://www.w3.org/2001/XMLSchema-instance\" ><\n " +
23+ " public void testDoesNotAffectHierarchy() throws Exception\n " +
24+ " {\n " +
25+ " String xml = \" <Parent xmlns:xsi=\\ \" http://www.w3.org/2001/XMLSchema-instance\\ \" >\" \n " +
26+ " + \" <level1>\" \n " +
27+ " + \" <level2>\" \n " +
28+ " + \" <ignored xsi:nil=\\ \" true\\ \" />\" \n " +
29+ " + \" <field>test-value</field>\" \n " +
30+ " + \" </level2>\" \n " +
31+ " + \" </level1>\" \n " +
32+ " + \" </Parent>\" ;\n " +
33+ " Parent bean = MAPPER.readValue(xml, Parent.class);\n " +
34+ "\n " +
35+ " assertNotNull(bean);\n " +
36+ "\n " +
37+ " // this should not be set, but having an xsi:nil field before it causes it to set the next field on the wrong class\n " +
38+ " assertEquals(\" test-value\" , bean.level1.field);\n " +
39+ "\n " +
40+ " // fails because field is set on level1 instead of on level2\n " +
41+ " assertEquals(\" test-value\" , bean.level1.level2.field);\n " +
42+ " }\n " +
43+ "d xsi:nil='true' /></DoubleWrapper>" ,
3744 DoubleWrapper .class );
3845 assertNotNull (bean );
3946 assertNull (bean .d );
@@ -71,25 +78,4 @@ public void testRootPojoAsNonNull() throws Exception
7178 Point .class );
7279 assertNotNull (bean );
7380 }
74-
75- public void testDoesNotAffectHierarchy () throws Exception
76- {
77- String xml = "<Parent xmlns:xsi=\" http://www.w3.org/2001/XMLSchema-instance\" >"
78- + "<level1>"
79- + "<level2>"
80- + "<ignored xsi:nil=\" true\" />"
81- + "<field>test-value</field>"
82- + "</level2>"
83- + "</level1>"
84- + "</Parent>" ;
85- Parent bean = MAPPER .readValue (xml , Parent .class );
86-
87- assertNotNull (bean );
88-
89- // this should not be set, but having an xsi:nil field before it causes it to set the next field on the wrong class
90- assertEquals ("test-value" , bean .level1 .field );
91-
92- // fails because field is set on level1 instead of on level2
93- assertEquals ("test-value" , bean .level1 .level2 .field );
94- }
9581}
0 commit comments