Skip to content

Commit dbe9be2

Browse files
authored
Add failing tests for #714 (under tofix) (#715)
1 parent fd61dc6 commit dbe9be2

File tree

2 files changed

+69
-5
lines changed

2 files changed

+69
-5
lines changed

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.junit.jupiter.api.Test;
44

5+
import com.fasterxml.jackson.databind.DeserializationFeature;
56
import com.fasterxml.jackson.databind.JsonNode;
67
import com.fasterxml.jackson.databind.ObjectReader;
78
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
@@ -13,7 +14,7 @@ public class XsiNilBasicTest extends XmlTestUtil
1314
{
1415
private final static String XSI_NS_DECL = "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'";
1516

16-
protected static class DoubleWrapper {
17+
public static class DoubleWrapper {
1718
public Double d;
1819

1920
public DoubleWrapper() { }
@@ -22,14 +23,17 @@ public DoubleWrapper(Double value) {
2223
}
2324
}
2425

25-
protected static class DoubleWrapper2 {
26+
public static class DoubleWrapper2 {
2627
public Double a = 100.0; // init to ensure it gets overwritten
2728
public Double b = 200.0;
2829

2930
public DoubleWrapper2() { }
3031
}
3132

32-
private final XmlMapper MAPPER = newMapper();
33+
// 30-Jan-2025, tatu: To tease out [dataformat-xml#714] let's do this:
34+
private final XmlMapper MAPPER = mapperBuilder()
35+
.enable(DeserializationFeature.FAIL_ON_TRAILING_TOKENS)
36+
.build();
3337

3438
@Test
3539
public void testWithDoubleAsNull() throws Exception
@@ -94,6 +98,8 @@ public void testWithDoubleAsMixed() throws Exception
9498
assertEquals(defaultValue.b, bean.b);
9599
}
96100

101+
// [dataformat-xml#714]: trailing END_OBJECT
102+
/*
97103
@Test
98104
public void testRootPojoAsNull() throws Exception
99105
{
@@ -102,6 +108,7 @@ public void testRootPojoAsNull() throws Exception
102108
Point.class);
103109
assertNull(bean);
104110
}
111+
*/
105112

106113
@Test
107114
public void testRootPojoAsNonNull() throws Exception
@@ -142,6 +149,8 @@ public void testDisableXsiNilLeafProcessing() throws Exception
142149

143150
// [dataformat-xml#468]: Allow disabling xsi:nil special handling
144151

152+
// [dataformat-xml#714]: trailing END_OBJECT
153+
/*
145154
@Test
146155
public void testDisableXsiNilRootProcessing() throws Exception
147156
{
@@ -153,10 +162,10 @@ public void testDisableXsiNilRootProcessing() throws Exception
153162
154163
// 07-Jul-2021, tatu: Alas! 2.x sets format feature flags too late to
155164
// affect root element (3.0 works correctly). So cannot test
156-
/*
165+
157166
ObjectReader noXsiNilReader = r.without(FromXmlParser.Feature.PROCESS_XSI_NIL);
158167
assertEquals(a2q("{'nil':'true'}"),
159168
noXsiNilReader.readValue(DOC).toString());
160-
*/
161169
}
170+
*/
162171
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.fasterxml.jackson.dataformat.xml.tofix;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import com.fasterxml.jackson.databind.DeserializationFeature;
6+
import com.fasterxml.jackson.databind.JsonNode;
7+
import com.fasterxml.jackson.databind.ObjectReader;
8+
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
9+
import com.fasterxml.jackson.dataformat.xml.XmlTestUtil;
10+
import com.fasterxml.jackson.dataformat.xml.deser.FromXmlParser;
11+
import com.fasterxml.jackson.dataformat.xml.testutil.failure.JacksonTestFailureExpected;
12+
13+
import static org.junit.jupiter.api.Assertions.*;
14+
15+
public class XsiNilBasic714Test extends XmlTestUtil
16+
{
17+
private final static String XSI_NS_DECL = "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'";
18+
19+
// 30-Jan-2025, tatu: To tease out [dataformat-xml#714] let's do this:
20+
private final XmlMapper MAPPER = mapperBuilder()
21+
.enable(DeserializationFeature.FAIL_ON_TRAILING_TOKENS)
22+
.build();
23+
24+
// [dataformat-xml#714]: trailing END_OBJECT
25+
@JacksonTestFailureExpected
26+
@Test
27+
public void testRootPojoAsNull() throws Exception
28+
{
29+
Point bean = MAPPER.readValue(
30+
"<Point "+XSI_NS_DECL+" xsi:nil='true' />",
31+
Point.class);
32+
assertNull(bean);
33+
}
34+
35+
// [dataformat-xml#468]: Allow disabling xsi:nil special handling
36+
37+
// [dataformat-xml#714]: trailing END_OBJECT
38+
@JacksonTestFailureExpected
39+
@Test
40+
public void testDisableXsiNilRootProcessing() throws Exception
41+
{
42+
final ObjectReader r = MAPPER.readerFor(JsonNode.class);
43+
final String DOC = "<Point "+XSI_NS_DECL+" xsi:nil='true'></Point>";
44+
45+
// with default processing:
46+
assertEquals("null", r.readValue(DOC).toString());
47+
48+
// 07-Jul-2021, tatu: Alas! 2.x sets format feature flags too late to
49+
// affect root element (3.0 works correctly). So cannot test
50+
51+
ObjectReader noXsiNilReader = r.without(FromXmlParser.Feature.PROCESS_XSI_NIL);
52+
assertEquals(a2q("{'nil':'true'}"),
53+
noXsiNilReader.readValue(DOC).toString());
54+
}
55+
}

0 commit comments

Comments
 (0)