Deserialization of null String values in Arrays / Collections not working as expected · Issue #584 · FasterXML/jackson-dataformat-xml (original) (raw)

Environment: Jackson Dataformat XML 2.14.2

We are trying to serialize and deserialize arrays or collections of Strings containing both empty and null values.
We noticed that nulls are handled correctly when serializing:

When parsing this values back null elements have become empty ("") values.
We tried:

Testing showed that with simple String attributes inside a class both null and empty values are correctly handled during deserialization, as expected (see also #354).

The behavior of String values inside collections should be aligned to how String attributes inside objects are handled.

Here's an example:

XmlMapper xmlMapper = new XmlMapper(); xmlMapper.enable( ToXmlGenerator.Feature.WRITE_NULLS_AS_XSI_NIL ); xmlMapper.enable( FromXmlParser.Feature.PROCESS_XSI_NIL );

String string = xmlMapper.writeValueAsString( new String[] { "", "test", null, "test2" } ); // string: testtest2 String[] parsed = xmlMapper.readValue( string, String[].class ); // parsed: ["", "test", "", "test2"]