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
In JSON.NET, at least as of v4.5.6, it detects the DataContract of the base class and assumes opt-in serialization. Since Address is not decorated with the DataMember attribute it does not get serialized.
This is by design according to James Newton-King with no planned change.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With