Skip to content

Commit

Permalink
Add a failing test for #378
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jan 4, 2020
1 parent af5a9fb commit 85a7f10
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 5 deletions.
21 changes: 21 additions & 0 deletions pom.xml
Expand Up @@ -116,6 +116,27 @@ Some data-binding types overridden as well (ObjectMapper sub-classed as XmlMappe

<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.4</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<!-- attached to Maven test phase -->
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<!-- Inherited from oss-base. Generate PackageVersion.java.-->
<groupId>com.google.code.maven-replacer-plugin</groupId>
Expand Down
Expand Up @@ -5,6 +5,8 @@

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

protected static class DoubleWrapper {
public Double d;

Expand All @@ -19,13 +21,13 @@ public DoubleWrapper(Double value) {
public void testWithDoubleAsNull() throws Exception
{
DoubleWrapper bean = MAPPER.readValue(
"<DoubleWrapper xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><d xsi:nil='true' /></DoubleWrapper>",
"<DoubleWrapper "+XSI_NS_DECL+"><d xsi:nil='true' /></DoubleWrapper>",
DoubleWrapper.class);
assertNotNull(bean);
assertNull(bean.d);

bean = MAPPER.readValue(
"<DoubleWrapper xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><d xsi:nil='true'> </d></DoubleWrapper>",
"<DoubleWrapper "+XSI_NS_DECL+"><d xsi:nil='true'> </d></DoubleWrapper>",
DoubleWrapper.class);
assertNotNull(bean);
assertNull(bean.d);
Expand All @@ -36,7 +38,7 @@ public void testWithDoubleAsNull() throws Exception
public void testWithDoubleAsNonNull() throws Exception
{
DoubleWrapper bean = MAPPER.readValue(
"<DoubleWrapper xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><d xsi:nil='false'>0.25</d></DoubleWrapper>",
"<DoubleWrapper "+XSI_NS_DECL+"><d xsi:nil='false'>0.25</d></DoubleWrapper>",
DoubleWrapper.class);
assertNotNull(bean);
assertEquals(Double.valueOf(0.25), bean.d);
Expand All @@ -45,15 +47,15 @@ public void testWithDoubleAsNonNull() throws Exception
public void testRootPojoAsNull() throws Exception
{
Point bean = MAPPER.readValue(
"<Point xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:nil='true' />",
"<Point "+XSI_NS_DECL+" xsi:nil='true' />",
Point.class);
assertNull(bean);
}

public void testRootPojoAsNonNull() throws Exception
{
Point bean = MAPPER.readValue(
"<Point xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:nil='false'></Point>",
"<Point "+XSI_NS_DECL+" xsi:nil='false'></Point>",
Point.class);
assertNotNull(bean);
}
Expand Down
@@ -0,0 +1,41 @@
package com.fasterxml.jackson.dataformat.xml.failing;

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

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

protected static class StringPair {
public String first, second;
}

private final XmlMapper MAPPER = newMapper();

// [dataformat-xml#378]
public void testWithStringAsNull() throws Exception
{
StringPair bean;

bean = MAPPER.readValue(
"<StringPair "+XSI_NS_DECL+"><first>not null</first><second xsi:nil='true' /></StringPair>",
StringPair.class);
assertNotNull(bean);
assertEquals("not null", bean.first);
assertNull(bean.second);
}

// [dataformat-xml#378]
public void testWithStringAsNull2() throws Exception
{
StringPair bean;

bean = MAPPER.readValue(
"<StringPair "+XSI_NS_DECL+"><first xsi:nil='true' /><second>not null</second></StringPair>",
StringPair.class);
assertNotNull(bean);
assertNull(bean.first);
assertEquals("not null", bean.second);
}
}

0 comments on commit 85a7f10

Please sign in to comment.