XSerializer icon indicating copy to clipboard operation
XSerializer copied to clipboard

ListSerializer AlwaysEmitNil() forces output of null grandchild items

Open ghost opened this issue 8 years ago • 1 comments

Regarding the ListSerializer, what is the point of AlwaysEmitNil() if null items are not serialized via the CustomSerializer class when the ShouldEmitNil option is false (the default)? The ListSerializer class calls upon the following CustomSerializer method to emit the list item instance:

        public void SerializeObject(XSerializerXmlTextWriter writer, object instance, ISerializeOptions options)
        {
            if (instance == null && !options.ShouldEmitNil)
            {
                return;
            }
            <<< snip >>>
       }

The unfortunate impact of AlwaysEmitNil() is that it cascades down the serialization pipeline forcing the output of null grandchild items. From what I can tell, the integrity of the list can survive without the AlwaysEmitNil() behavior.

ghost avatar Feb 13 '17 02:02 ghost