jackson-dataformat-xml: null-handling ignored
With 2.12.1-SNAPSHOT the following code:
XML_MAPPER = new XmlMapper();
XML_MAPPER.configOverride(List.class).setSetterInfo(JsonSetter.Value.forValueNulls(Nulls.AS_EMPTY));
XML_MAPPER.configOverride(Set.class).setSetterInfo(JsonSetter.Value.forValueNulls(Nulls.AS_EMPTY));
XML_MAPPER.configOverride(Map.class).setSetterInfo(JsonSetter.Value.forValueNulls(Nulls.AS_EMPTY));
XML_MAPPER.enable(FromXmlParser.Feature.EMPTY_ELEMENT_AS_NULL);
List<LoggerTO> original = new ArrayList<>();
StringWriter writer = new StringWriter();
XML_MAPPER.writeValue(writer, original);
List<LoggerTO> actual = XML_MAPPER.readValue(writer.toString(), new TypeReference<List<LoggerTO>>() {
});
assertEquals(original, actual);
fails with message
org.opentest4j.AssertionFailedError: expected: <[]> but was: <null>
I have verified that serialization produces
<ArrayList/>
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 22 (12 by maintainers)
For what it is worth, empty element like
<ArrayList></ArrayList>
(or<ArrayList />
) should be deserialized as emptyList
with 2.12, as long as you do NOT enableFromXmlParser.Feature.EMPTY_ELEMENT_AS_NULL
. This was not the case with 2.11, regardless of setting as handling of empty elements had problems – mostly because at low level such elements would be equivalent to JSON empty String value. Support for this case was improved injackson-databind
2.12, to let XML module work better for this relatively common case.I hope it is now possible to get things to work in a usable way: unfortunately the full combination of various aspects is not easy to reason about and it can be frustrating to find a good combination. Especially when attempting to make things work the same way against different versions.
I am planning to release
2.12.1
very soon now, for what that is worth; there are a few important fixes.