I noticed that when serializing/deserializing a POCO class with JSON.NET that derives from a base class that uses explicit DataContract attributes then any POCO properties on the derived class are ignored.
For example, in this example, "Address" is not serialized/deserialized:
[DataContract]
public class MyBaseClass
{
[DataMember(Name = "SomeName")]
public string Name { get; set; }
}
public class MyDerivedClass : MyBaseClass
{
public string Address { get; set; }
}
Is that intentional?
FWIW, it does seem that DataContractSerializer (at least the XML one) does the "right thing" here and serializes/deserializes "Address".
Thanks!
Henrik
DataContractSerializer
will not serialize the subclass at all if it is not decorated with[DataContract]
; instead it throws an exception. This seems to be consistent with the documentation for theDataContractAttribute
, which states that it is not inherited from the base class. – Brian Rogers