Skip to content

Commit 7f08139

Browse files
lkorthcowtowncoder
authored andcommitted
Add test for xsi:nil hierarchy bug (#366)
1 parent 583a3bd commit 7f08139

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

src/test/java/com/fasterxml/jackson/dataformat/xml/deser/XsiNil354Test.java

+36-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@ 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+
1731
private final XmlMapper MAPPER = newMapper();
1832

1933
public void testWithDoubleAsNull() throws Exception
@@ -29,7 +43,7 @@ public void testWithDoubleAsNull() throws Exception
2943
DoubleWrapper.class);
3044
assertNotNull(bean);
3145
assertNull(bean.d);
32-
46+
3347
// actually we should perhaps also verify there is no content but... for now, let's leave it.
3448
}
3549

@@ -57,4 +71,25 @@ public void testRootPojoAsNonNull() throws Exception
5771
Point.class);
5872
assertNotNull(bean);
5973
}
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+
}
6095
}

0 commit comments

Comments
 (0)