Json.Net has no problem serializing an overridden property in a child class.
public override ICollection<Person> Persons { get; set; }
But if I try to use new on the property, the serialization fails. There’s no exception; Persons are just never serialized.
public new ICollection<Person> Persons { get; set; }
Why is this?
(This example doesn’t make much sense, I know. It’s only an example. The goal later is to be able to change datatype of the property public new ICollection<PersonDto> Persons { get; set; })
I discovered a simpler way to solved this without having to create a custom
JsonConverterIf you put the attribute
JsonPropertyover the property it works.I don’t know why Json.Net needs the attribute here. Normally it serializes everything that isn’t decorated with
JsonIgnore. If someone knows, you’re welcome to drop a comment.