Skip to content

Commit 12d56ba

Browse files
committed
Trying to resolve null/"" problem
1 parent 6c7c96a commit 12d56ba

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/main/java/com/fasterxml/jackson/dataformat/xml/XmlMapper.java

+3
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ public Builder(XmlFactory f) {
7676

7777
// 04-May-2018, tatu: Important! Let's also default `String` `null` handling to coerce
7878
// to empty string -- this lets us induce `null` from empty tags first
79+
80+
// 08-Sep-2019, tatu: Note: this could conflict with [dataformat-xml#354] (true `null`s
81+
// with `xsi:nil`) unless we are careful to distinguish empty/null
7982
_configOverrides.findOrCreateOverride(String.class)
8083
.setNullHandling(JsonSetter.Value.forValueNulls(Nulls.AS_EMPTY));
8184
}

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

+12-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.fasterxml.jackson.databind.*;
77
import com.fasterxml.jackson.databind.deser.std.StdScalarDeserializer;
88
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
9+
import com.fasterxml.jackson.databind.util.AccessPattern;
910

1011
/**
1112
* Custom variant used instead of "plain" {@code StringDeserializer} to handle
@@ -22,10 +23,20 @@ public class XmlStringDeserializer
2223
public boolean isCachable() { return true; }
2324

2425
@Override
25-
public Object getEmptyValue(DeserializationContext ctxt) throws JsonMappingException {
26+
public Object getEmptyValue(DeserializationContext ctxt) {
2627
return "";
2728
}
2829

30+
@Override
31+
public Object getNullValue(DeserializationContext ctxt) {
32+
return null;
33+
}
34+
35+
@Override
36+
public AccessPattern getEmptyAccessPattern() {
37+
return AccessPattern.CONSTANT;
38+
}
39+
2940
@Override
3041
public String deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
3142
{

0 commit comments

Comments
 (0)