Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XML containing xsi:nil is improperly parsed #366

Merged
merged 1 commit into from Oct 23, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -14,6 +14,20 @@ public DoubleWrapper(Double value) {
}
}

protected static class Parent {
public Level1 level1;
}

protected static class Level1 {
public Level2 level2;
public String field; // this should not be needed, but an unknown element is thrown without it
}

protected static class Level2 {
public String ignored;
public String field;
}

private final XmlMapper MAPPER = newMapper();

public void testWithDoubleAsNull() throws Exception
Expand All @@ -29,7 +43,7 @@ public void testWithDoubleAsNull() throws Exception
DoubleWrapper.class);
assertNotNull(bean);
assertNull(bean.d);

// actually we should perhaps also verify there is no content but... for now, let's leave it.
}

Expand Down Expand Up @@ -57,4 +71,25 @@ public void testRootPojoAsNonNull() throws Exception
Point.class);
assertNotNull(bean);
}

public void testDoesNotAffectHierarchy() throws Exception
{
String xml = "<Parent xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"
+ "<level1>"
+ "<level2>"
+ "<ignored xsi:nil=\"true\"/>"
+ "<field>test-value</field>"
+ "</level2>"
+ "</level1>"
+ "</Parent>";
Parent bean = MAPPER.readValue(xml, Parent.class);

assertNotNull(bean);

// this should not be set, but having an xsi:nil field before it causes it to set the next field on the wrong class
assertEquals("test-value", bean.level1.field);

// fails because field is set on level1 instead of on level2
assertEquals("test-value", bean.level1.level2.field);
}
}