This is a question about serialization in general, but in particular I am using ServiceStack's excellent serializers in my .NET code.
Should the deserializers set null references on properties? It seems like currently it ignores null references and just allows such fields to be set according the class's defaults. For example, this test fails:
[TestMethod]
public void Deserialize_WithNullCollection_CollectionIsNull() {
var serializer = new ServiceStack.Text.TypeSerializer<Foo>();
Foo item = new Foo() { Strings = null };
Foo result = serializer.DeserializeFromString(serializer.SerializeToString(item));
Assert.IsNull(result.Strings);
}
public class Foo {
public Foo() {
Strings = new List<string>();
}
public List<string> Strings { get; set; }
}
I believe this perhaps this test ought to succeed, but it does not--item.Foo is an empty list rather than a null reference. It seems to me that null references are part of an object's state just like any actual reference is. Am I right or wrong?