Skip to content

Commit b5bbfa6

Browse files
committed
Add a failing test case for #162
1 parent d9fc9c8 commit b5bbfa6

File tree

3 files changed

+41
-13
lines changed

3 files changed

+41
-13
lines changed

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

+10-12
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class FromXmlParser
2727
* String ("").
2828
*/
2929
public final static String DEFAULT_UNNAMED_TEXT_PROPERTY = "";
30-
30+
3131
/**
3232
* Enumeration that defines all togglable features for XML parsers.
3333
* None defined so far (2.6), so just a placeholder.
@@ -319,8 +319,7 @@ public void addVirtualWrapping(Set<String> namesToWrap)
319319
* the current event.
320320
*/
321321
@Override
322-
public String getCurrentName()
323-
throws IOException, JsonParseException
322+
public String getCurrentName() throws IOException
324323
{
325324
// [JACKSON-395]: start markers require information from parent
326325
String name;
@@ -705,7 +704,7 @@ private void _updateState(JsonToken t)
705704
*/
706705

707706
@Override
708-
public String getText() throws IOException, JsonParseException
707+
public String getText() throws IOException
709708
{
710709
if (_currToken == null) {
711710
return null;
@@ -722,12 +721,12 @@ public String getText() throws IOException, JsonParseException
722721

723722
// @since 2.1
724723
@Override
725-
public final String getValueAsString() throws IOException, JsonParseException {
724+
public final String getValueAsString() throws IOException {
726725
return getValueAsString(null);
727726
}
728727

729728
@Override
730-
public String getValueAsString(String defValue) throws IOException, JsonParseException
729+
public String getValueAsString(String defValue) throws IOException
731730
{
732731
JsonToken t = _currToken;
733732
if (t == null) {
@@ -770,19 +769,19 @@ public String getValueAsString(String defValue) throws IOException, JsonParseExc
770769
}
771770

772771
@Override
773-
public char[] getTextCharacters() throws IOException, JsonParseException {
772+
public char[] getTextCharacters() throws IOException {
774773
String text = getText();
775774
return (text == null) ? null : text.toCharArray();
776775
}
777776

778777
@Override
779-
public int getTextLength() throws IOException, JsonParseException {
778+
public int getTextLength() throws IOException {
780779
String text = getText();
781780
return (text == null) ? 0 : text.length();
782781
}
783782

784783
@Override
785-
public int getTextOffset() throws IOException, JsonParseException {
784+
public int getTextOffset() throws IOException {
786785
return 0;
787786
}
788787

@@ -803,14 +802,13 @@ public boolean hasTextCharacters()
803802
*/
804803

805804
@Override
806-
public Object getEmbeddedObject() throws IOException, JsonParseException {
805+
public Object getEmbeddedObject() throws IOException {
807806
// no way to embed POJOs for now...
808807
return null;
809808
}
810809

811810
@Override
812-
public byte[] getBinaryValue(Base64Variant b64variant)
813-
throws IOException, JsonParseException
811+
public byte[] getBinaryValue(Base64Variant b64variant) throws IOException
814812
{
815813
if (_currToken != JsonToken.VALUE_STRING &&
816814
(_currToken != JsonToken.VALUE_EMBEDDED_OBJECT || _binaryValue == null)) {

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public String toString() {
1414
return "[a="+a+",b="+b+"]";
1515
}
1616
}
17-
17+
1818
/*
1919
/**********************************************************
2020
/* Unit tests
@@ -38,6 +38,7 @@ public void testEmptyStringElement() throws Exception
3838
assertNotNull(bean);
3939
// empty String or null?
4040
// 22-Sep-2012, tatu: Seems to be 'null', but should probably be fixed to ""
41+
// Also see [dataformat-xml#162]
4142
// assertEquals("", bean.text);
4243
assertNull(bean.text);
4344
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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 TestStringValues162 extends XmlTestBase
7+
{
8+
static class Name {
9+
public String first;
10+
public String last;
11+
}
12+
13+
/*
14+
/**********************************************************
15+
/* Unit tests
16+
/**********************************************************
17+
*/
18+
19+
private final XmlMapper MAPPER = new XmlMapper();
20+
21+
public void testEmptyString162() throws Exception
22+
{
23+
Name name = MAPPER.readValue("<name><first>Ryan</first><last></last></name>",
24+
Name.class);
25+
assertNotNull(name);
26+
assertEquals("Ryan", name.first);
27+
assertEquals("", name.last);
28+
}
29+
}

0 commit comments

Comments
 (0)