Skip to content

Commit 9df7dec

Browse files
committed
Fix #167
1 parent b2b6373 commit 9df7dec

File tree

4 files changed

+22
-30
lines changed

4 files changed

+22
-30
lines changed

release-notes/VERSION

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Project: jackson-dataformat-xml
77
2.7.0 (not yet released)
88

99
#156: Add `XmlMapper.setDefaultUseWrapper()` for convenience.
10+
#167: Exception on deserializing empty element with an xsi attribute
1011
#169: Fail to deserialize "empty" polymorphic classes
1112

1213
2.6.5 (not yet released)

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,12 @@ protected String convertToString() throws IOException
270270
}
271271
try {
272272
String text = _collectUntilTag();
273-
if (text != null && _xmlReader.getEventType() == XMLStreamReader.END_ELEMENT) {
273+
// 23-Dec-2015, tatu: Used to require text not to be null, but as per
274+
// [dataformat-xml#167], empty tag does count
275+
if (_xmlReader.getEventType() == XMLStreamReader.END_ELEMENT) {
276+
if (text == null) {
277+
text = "";
278+
}
274279
if (_currentWrapper != null) {
275280
_currentWrapper = _currentWrapper.getParent();
276281
}

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

+15
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ public String toString() {
1515
}
1616
}
1717

18+
static class Issue167Bean {
19+
public String d;
20+
}
21+
1822
/*
1923
/**********************************************************
2024
/* Unit tests
@@ -90,4 +94,15 @@ public void testStringArrayWithAttribute() throws Exception
9094
assertEquals("Bulla", beans[1].text);
9195
assertEquals("Good stuff", beans[2].text);
9296
}
97+
98+
public void testEmptyElementToString() throws Exception
99+
{
100+
final String XML =
101+
"<a xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>\n"+
102+
"<d xsi:nil='true'/>\n"+
103+
"</a>\n";
104+
Issue167Bean result = MAPPER.readValue(XML, Issue167Bean.class);
105+
assertNotNull(result);
106+
assertEquals("", result.d);
107+
}
93108
}

src/test/java/com/fasterxml/jackson/dataformat/xml/failing/EmptyElement167Test.java

-29
This file was deleted.

0 commit comments

Comments
 (0)