Skip to content

Commit c801a96

Browse files
committed
Add a failing test for #354
1 parent c7a2478 commit c801a96

File tree

4 files changed

+50
-7
lines changed

4 files changed

+50
-7
lines changed

src/main/java/com/fasterxml/jackson/dataformat/xml/deser/XmlTokenStream.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
* abstract out all irrelevant details, and to expose equivalent of flat token
1515
* stream with no "fluff" tokens (comments, processing instructions, mixed
1616
* content) all of which is just to simplify
17-
* actual higher-level conversion to JSON tokens
17+
* actual higher-level conversion to JSON tokens.
18+
*<p>
19+
* Beyond initial idea there are also couple of other detours like ability
20+
* to "replay" some tokens, add virtual wrappers (ironically to support "unwrapped"
21+
* array values), and to unroll "Objects" into String values in some cases.
1822
*/
1923
public class XmlTokenStream
2024
{
@@ -146,7 +150,7 @@ protected void setFormatFeatures(int f) {
146150

147151
// DEBUGGING
148152
/*
149-
public int next() throws IOException
153+
public int next() throws XMLStreamException
150154
{
151155
int n = next0();
152156
switch (n) {
@@ -270,6 +274,10 @@ protected void skipAttributes()
270274
}
271275
}
272276

277+
/**
278+
* Helper method called by XML String deserializer to concatenate textual contents
279+
* contained in logical "Object": mostly just to skip attribute values.
280+
*/
273281
protected String convertToString() throws XMLStreamException
274282
{
275283
// only applicable to cases where START_OBJECT was induced by attributes

src/test/java/com/fasterxml/jackson/dataformat/xml/XmlTestBase.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public boolean equals(Object o)
104104
return true;
105105
}
106106
}
107-
107+
108108
protected static class StringBean
109109
{
110110
public String text;
@@ -118,7 +118,7 @@ public String toString() {
118118
return "\""+text+"\"";
119119
}
120120
}
121-
121+
122122
/**
123123
* Simple wrapper around String type, usually to test value
124124
* conversions or wrapping
@@ -131,7 +131,7 @@ public StringWrapper(String value) {
131131
str = value;
132132
}
133133
}
134-
134+
135135
protected static class IntWrapper {
136136
public int i;
137137

@@ -141,7 +141,6 @@ public IntWrapper(int value) {
141141
}
142142
}
143143

144-
// since 2.9.6
145144
public static class Point {
146145
public int x, y;
147146

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static class Issue167Bean {
2727
/**********************************************************
2828
*/
2929

30-
private final XmlMapper MAPPER = new XmlMapper();
30+
private final XmlMapper MAPPER = newMapper();
3131

3232
public void testSimpleStringElement() throws Exception
3333
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 XsiNil354Test extends XmlTestBase
7+
{
8+
protected static class DoubleWrapper {
9+
public Double d;
10+
11+
public DoubleWrapper() { }
12+
public DoubleWrapper(Double value) {
13+
d = value;
14+
}
15+
}
16+
17+
private final XmlMapper MAPPER = newMapper();
18+
19+
public void testWithDoubleAsNull() throws Exception
20+
{
21+
DoubleWrapper bean = MAPPER.readValue(
22+
"<DoubleWrapper xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><d xsi:nil='true'></DoubleWrapper>",
23+
DoubleWrapper.class);
24+
assertNotNull(bean);
25+
assertNull(bean.d);
26+
}
27+
28+
public void testWithDoubleAsNonNull() throws Exception
29+
{
30+
DoubleWrapper bean = MAPPER.readValue(
31+
"<DoubleWrapper xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><d xsi:nil='false'>0.25</DoubleWrapper>",
32+
DoubleWrapper.class);
33+
assertNotNull(bean);
34+
assertEquals(Double.valueOf(0.25), bean.d);
35+
}
36+
}

0 commit comments

Comments
 (0)