Skip to content

Commit 85a7f10

Browse files
committed
Add a failing test for #378
1 parent af5a9fb commit 85a7f10

File tree

3 files changed

+69
-5
lines changed

3 files changed

+69
-5
lines changed

pom.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,27 @@ Some data-binding types overridden as well (ObjectMapper sub-classed as XmlMappe
116116

117117
<build>
118118
<plugins>
119+
<plugin>
120+
<groupId>org.jacoco</groupId>
121+
<artifactId>jacoco-maven-plugin</artifactId>
122+
<version>0.8.4</version>
123+
<executions>
124+
<execution>
125+
<goals>
126+
<goal>prepare-agent</goal>
127+
</goals>
128+
</execution>
129+
<!-- attached to Maven test phase -->
130+
<execution>
131+
<id>report</id>
132+
<phase>test</phase>
133+
<goals>
134+
<goal>report</goal>
135+
</goals>
136+
</execution>
137+
</executions>
138+
</plugin>
139+
119140
<plugin>
120141
<!-- Inherited from oss-base. Generate PackageVersion.java.-->
121142
<groupId>com.google.code.maven-replacer-plugin</groupId>

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
public class XsiNil354Test extends XmlTestBase
77
{
8+
private final static String XSI_NS_DECL = "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'";
9+
810
protected static class DoubleWrapper {
911
public Double d;
1012

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

2729
bean = MAPPER.readValue(
28-
"<DoubleWrapper xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><d xsi:nil='true'> </d></DoubleWrapper>",
30+
"<DoubleWrapper "+XSI_NS_DECL+"><d xsi:nil='true'> </d></DoubleWrapper>",
2931
DoubleWrapper.class);
3032
assertNotNull(bean);
3133
assertNull(bean.d);
@@ -36,7 +38,7 @@ public void testWithDoubleAsNull() throws Exception
3638
public void testWithDoubleAsNonNull() throws Exception
3739
{
3840
DoubleWrapper bean = MAPPER.readValue(
39-
"<DoubleWrapper xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><d xsi:nil='false'>0.25</d></DoubleWrapper>",
41+
"<DoubleWrapper "+XSI_NS_DECL+"><d xsi:nil='false'>0.25</d></DoubleWrapper>",
4042
DoubleWrapper.class);
4143
assertNotNull(bean);
4244
assertEquals(Double.valueOf(0.25), bean.d);
@@ -45,15 +47,15 @@ public void testWithDoubleAsNonNull() throws Exception
4547
public void testRootPojoAsNull() throws Exception
4648
{
4749
Point bean = MAPPER.readValue(
48-
"<Point xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:nil='true' />",
50+
"<Point "+XSI_NS_DECL+" xsi:nil='true' />",
4951
Point.class);
5052
assertNull(bean);
5153
}
5254

5355
public void testRootPojoAsNonNull() throws Exception
5456
{
5557
Point bean = MAPPER.readValue(
56-
"<Point xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:nil='false'></Point>",
58+
"<Point "+XSI_NS_DECL+" xsi:nil='false'></Point>",
5759
Point.class);
5860
assertNotNull(bean);
5961
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.fasterxml.jackson.dataformat.xml.failing;
2+
3+
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
4+
import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
5+
6+
public class XsiNil378Test extends XmlTestBase
7+
{
8+
private final static String XSI_NS_DECL = "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'";
9+
10+
protected static class StringPair {
11+
public String first, second;
12+
}
13+
14+
private final XmlMapper MAPPER = newMapper();
15+
16+
// [dataformat-xml#378]
17+
public void testWithStringAsNull() throws Exception
18+
{
19+
StringPair bean;
20+
21+
bean = MAPPER.readValue(
22+
"<StringPair "+XSI_NS_DECL+"><first>not null</first><second xsi:nil='true' /></StringPair>",
23+
StringPair.class);
24+
assertNotNull(bean);
25+
assertEquals("not null", bean.first);
26+
assertNull(bean.second);
27+
}
28+
29+
// [dataformat-xml#378]
30+
public void testWithStringAsNull2() throws Exception
31+
{
32+
StringPair bean;
33+
34+
bean = MAPPER.readValue(
35+
"<StringPair "+XSI_NS_DECL+"><first xsi:nil='true' /><second>not null</second></StringPair>",
36+
StringPair.class);
37+
assertNotNull(bean);
38+
assertNull(bean.first);
39+
assertEquals("not null", bean.second);
40+
}
41+
}

0 commit comments

Comments
 (0)