Skip to content

Commit 0a77f33

Browse files
committed
Fix #359 by removing "String null coercion" setting, fixing tests
1 parent 1597517 commit 0a77f33

File tree

5 files changed

+10
-24
lines changed

5 files changed

+10
-24
lines changed

src/main/java/tools/jackson/dataformat/xml/XmlMapper.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
import javax.xml.stream.XMLStreamReader;
77
import javax.xml.stream.XMLStreamWriter;
88

9-
import com.fasterxml.jackson.annotation.JsonSetter;
109
import com.fasterxml.jackson.annotation.JsonTypeInfo;
11-
import com.fasterxml.jackson.annotation.Nulls;
1210

1311
import tools.jackson.core.*;
1412
import tools.jackson.core.type.TypeReference;
@@ -83,8 +81,10 @@ public Builder(XmlFactory f) {
8381
// to empty string -- this lets us induce `null` from empty tags firs
8482
// 08-Sep-2019, tatu: This causes [dataformat-xml#359] (follow-up for #354), but
8583
// can not simply be removed.
86-
_configOverrides.findOrCreateOverride(String.class)
87-
.setNullHandling(JsonSetter.Value.forValueNulls(Nulls.AS_EMPTY));
84+
// 19-Mar-2023, tatu: Nah. Let's not coerce to let `xsi:nil` works its magic
85+
86+
//_configOverrides.findOrCreateOverride(String.class)
87+
// .setNullHandling(JsonSetter.Value.forValueNulls(Nulls.AS_EMPTY));
8888

8989
// 13-May-2020, tatu: [dataformat-xml#377] Need to ensure we will keep XML-specific
9090
// Base64 default as "MIME" (not MIME-NO-LINEFEEDS), to preserve pre-2.12

src/main/java/tools/jackson/dataformat/xml/deser/FromXmlParser.java

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package tools.jackson.dataformat.xml.deser;
22

33
import java.io.IOException;
4-
import java.io.UncheckedIOException;
54
import java.io.Writer;
65
import java.math.BigDecimal;
76
import java.math.BigInteger;

src/test/java/tools/jackson/dataformat/xml/deser/NullConversionsSkipTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public void testSkipNullField1() throws Exception
5858
"<NullSkipField><noNulls>foo</noNulls><nullsOk /></NullSkipField>",
5959
NullSkipField.class);
6060
assertEquals("foo", result.noNulls);
61-
assertEquals("", result.nullsOk);
61+
assertNull(result.nullsOk);
6262
}
6363

6464
public void testSkipNullField2() throws Exception
@@ -77,7 +77,7 @@ public void testSkipNullMethod1() throws Exception
7777
"<NullSkipMethod><noNulls>foo</noNulls><nullsOk /></NullSkipMethod>",
7878
NullSkipMethod.class);
7979
assertEquals("foo", result._noNulls);
80-
assertEquals("", result._nullsOk);
80+
assertNull(result._nullsOk);
8181
}
8282

8383
public void testSkipNullMethod2() throws Exception
@@ -99,7 +99,7 @@ public void testSkipNullWithDefaults() throws Exception
9999
// String doc = "<StringValue><value></value></StringValue>";
100100
String doc = "<StringValue><value /></StringValue>";
101101
StringValue result = NULL_EXPOSING_MAPPER.readValue(doc, StringValue.class);
102-
assertEquals("", result.value);
102+
assertNull(result.value);
103103

104104
ObjectMapper mapper = mapperBuilder()
105105
.enable(FromXmlParser.Feature.EMPTY_ELEMENT_AS_NULL)

src/test/java/tools/jackson/dataformat/xml/deser/XsiNilForStringsTest.java

+2-11
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ protected static class StringPair {
1313

1414
private final XmlMapper MAPPER = newMapper();
1515

16-
// 04-Jan-2019, tatu: Due to default "Map Strings to Null values" coercion (see XmlMapper),
17-
// tests for `null` handling are not quite right for 3.x... ideally would probably
18-
// NOT use coercion, maybe, or (if possible) avoid doing that for `xsi:nil` induced
19-
// reliable one. But as of now not 100% clear how this could be done so comment out tests
20-
2116
// [dataformat-xml#378]
2217
public void testWithStringAsNull() throws Exception
2318
{
@@ -30,9 +25,7 @@ public void testWithStringAsNull() throws Exception
3025

3126
assertEquals("not null", bean.first);
3227

33-
// for 3.0:
34-
// assertNull(bean.second);
35-
assertEquals("", bean.second);
28+
assertNull(bean.second);
3629
}
3730

3831
// [dataformat-xml#378]
@@ -47,8 +40,6 @@ public void testWithStringAsNull2() throws Exception
4740
assertNotNull(bean);
4841
assertEquals("not null", bean.second);
4942

50-
// for 3.0:
51-
// assertNull(bean.first);
52-
assertEquals("", bean.first);
43+
assertNull(bean.first);
5344
}
5445
}

src/test/java/tools/jackson/dataformat/xml/lists/StringListRoundtripTest.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,7 @@ public void testStringPojo() throws Exception
264264
_stringPojoRoundtrip(MAPPER_READ_NULLS, false);
265265

266266
// xsi null enabled, should get back null
267-
268-
// 19-Mar-2023, tatu: I think this fails due to [dataformat-xml#359]:
269-
// need to comment out for now
270-
271-
// _stringPojoRoundtrip(MAPPER_READ_WRITE_NULLS, true);
267+
_stringPojoRoundtrip(MAPPER_READ_WRITE_NULLS, true);
272268

273269
// xsi null write enabled but processing disabled, should get back empty string
274270
_stringPojoRoundtrip(MAPPER_WRITE_NULLS, false);

0 commit comments

Comments
 (0)