-
-
Notifications
You must be signed in to change notification settings - Fork 230
Closed
Labels
2.15For issues planned for 2.15For issues planned for 2.15
Milestone
Description
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 null
s are handled correctly when serializing:
- null values are rendered as
<item />
, while empty strings as<item></item>
- enabling
ToXmlGenerator.Feature.WRITE_NULLS_AS_XSI_NIL
works as expected
When parsing this values back null
elements have become empty (""
) values.
We tried:
- explicitly enabling
FromXmlParser.Feature.PROCESS_XSI_NIL
, even though it should be enabled by default - enabling
FromXmlParser.Feature.EMPTY_ELEMENT_AS_NULL
But we still got empty String values as a result.
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: <Strings><item></item><item>test</item><item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/><item>test2</item></Strings>
String[] parsed = xmlMapper.readValue( string, String[].class );
// parsed: ["", "test", "", "test2"]
Metadata
Metadata
Assignees
Labels
2.15For issues planned for 2.15For issues planned for 2.15