Skip to content

Commit

Permalink
Merge pull request #218 from oistein/issue162
Browse files Browse the repository at this point in the history
Fix for #162 (XML Empty tag to Empty string)
  • Loading branch information
cowtowncoder authored Jun 21, 2017
2 parents 06b2537 + 6eda875 commit 2648916
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -371,21 +371,23 @@ private final int _next() throws XMLStreamException

private final String _collectUntilTag() throws XMLStreamException
{
String text = null;
if (_xmlReader.isEmptyElement()) {
_xmlReader.next();
return null;
}

StringBuilder text = new StringBuilder();

while (true) {
switch (_xmlReader.next()) {
case XMLStreamConstants.START_ELEMENT:
case XMLStreamConstants.END_ELEMENT:
case XMLStreamConstants.END_DOCUMENT:
return text;
// note: SPACE is ignorable (and seldom seen), not to be included
return text.toString();
// note: SPACE is ignorable (and seldom seen), not to be included
case XMLStreamConstants.CHARACTERS:
case XMLStreamConstants.CDATA:
if (text == null) {
text = _xmlReader.getText();
} else { // can be optimized in future, if need be:
text += _xmlReader.getText();
}
text.append(_xmlReader.getText());
break;
default:
// any other type (proc instr, comment etc) is just ignored
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.fasterxml.jackson.dataformat.xml.failing;
package com.fasterxml.jackson.dataformat.xml.deser;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -40,6 +40,14 @@ public void testEmptyString162() throws Exception
assertEquals("", name.last);
}

public void testEmptyElement() throws Exception
{
Name name = MAPPER.readValue("<name><first/><last></last></name>", Name.class);
assertNotNull(name);
assertNull(name.first);
assertEquals("", name.last);
}

public void testEmptyStringElement() throws Exception
{
// then with empty element
Expand Down

0 comments on commit 2648916

Please sign in to comment.