Skip to content

Commit

Permalink
Fix #366
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jan 5, 2020
1 parent c2fe22f commit f45aefc
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
5 changes: 5 additions & 0 deletions release-notes/CREDITS-2.x
Expand Up @@ -55,3 +55,8 @@ Rohit Narayanan (rohitnarayanan@github)

* Reported #351: XmlBeanSerializer serializes AnyGetters field even with FilterExceptFilter
(2.10.0)

Luke Korth (lkorth@github.com)

* Reported #366: XML containing xsi:nil is improperly parsed
(2.10.2)
2 changes: 2 additions & 0 deletions release-notes/VERSION-2.x
Expand Up @@ -6,6 +6,8 @@ Project: jackson-dataformat-xml

2.10.2 (not yet released)

#366: XML containing xsi:nil is improperly parsed
(reported by Luke K)
#378: Jackson 2.10.x fails to deserialize xsi:nil with multiple child elements
(reported by henrik242@github)

Expand Down
Expand Up @@ -3,7 +3,7 @@
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.dataformat.xml.XmlTestBase;

public class XsiNil378Test extends XmlTestBase
public class XsiNilForStringsTest extends XmlTestBase
{
private final static String XSI_NS_DECL = "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'";

Expand Down
@@ -1,9 +1,9 @@
package com.fasterxml.jackson.dataformat.xml.failing;
package com.fasterxml.jackson.dataformat.xml.deser;

import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.dataformat.xml.XmlTestBase;

public class XsiNil366Test extends XmlTestBase
public class XsiNilNestingTest extends XmlTestBase
{
// for [dataformat-xml#366]
protected static class Parent366 {
Expand All @@ -12,7 +12,6 @@ protected static class Parent366 {

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 {
Expand All @@ -26,21 +25,25 @@ protected static class Level2 {
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>"
+ " <level1>"
+ " <level2>"
+ " <ignored xsi:nil=\"true\"/>"
+ " <field>test-value</field>"
+ " </level2>"
+ " </level1>"
+ "</Parent>";
Parent366 bean = MAPPER.readValue(xml, Parent366.class);

assertNotNull(bean);
assertNotNull(bean.level1);
Level2 l2 = bean.level1.level2;
assertNotNull(l2);

// 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);
// should be null
assertNull(l2.ignored);
// and should not be null
assertNotNull(l2.field);

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

0 comments on commit f45aefc

Please sign in to comment.