Skip to content

Commit 6eda875

Browse files
author
Øistein Løvik
committed
Fix issue FasterXML#162
1 parent 4c3008e commit 6eda875

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

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

+10-8
Original file line numberDiff line numberDiff line change
@@ -371,21 +371,23 @@ private final int _next() throws XMLStreamException
371371

372372
private final String _collectUntilTag() throws XMLStreamException
373373
{
374-
String text = null;
374+
if (_xmlReader.isEmptyElement()) {
375+
_xmlReader.next();
376+
return null;
377+
}
378+
379+
StringBuilder text = new StringBuilder();
380+
375381
while (true) {
376382
switch (_xmlReader.next()) {
377383
case XMLStreamConstants.START_ELEMENT:
378384
case XMLStreamConstants.END_ELEMENT:
379385
case XMLStreamConstants.END_DOCUMENT:
380-
return text;
381-
// note: SPACE is ignorable (and seldom seen), not to be included
386+
return text.toString();
387+
// note: SPACE is ignorable (and seldom seen), not to be included
382388
case XMLStreamConstants.CHARACTERS:
383389
case XMLStreamConstants.CDATA:
384-
if (text == null) {
385-
text = _xmlReader.getText();
386-
} else { // can be optimized in future, if need be:
387-
text += _xmlReader.getText();
388-
}
390+
text.append(_xmlReader.getText());
389391
break;
390392
default:
391393
// any other type (proc instr, comment etc) is just ignored

src/test/java/com/fasterxml/jackson/dataformat/xml/failing/TestStringValues162.java renamed to src/test/java/com/fasterxml/jackson/dataformat/xml/deser/TestStringValues162.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.fasterxml.jackson.dataformat.xml.failing;
1+
package com.fasterxml.jackson.dataformat.xml.deser;
22

33
import java.util.ArrayList;
44
import java.util.List;
@@ -40,6 +40,14 @@ public void testEmptyString162() throws Exception
4040
assertEquals("", name.last);
4141
}
4242

43+
public void testEmptyElement() throws Exception
44+
{
45+
Name name = MAPPER.readValue("<name><first/><last></last></name>", Name.class);
46+
assertNotNull(name);
47+
assertNull(name.first);
48+
assertEquals("", name.last);
49+
}
50+
4351
public void testEmptyStringElement() throws Exception
4452
{
4553
// then with empty element

0 commit comments

Comments
 (0)