I use the NewtonSoft JSON.NET library to serialize the next class, where DTOBase can contain derived instances.
public class Command { public DTOBase CommandDTO { get; set; } }
Per in this article, you need to enable the JsonProperty attribute so that derived instances deserialize correctly
public class Command { [JsonProperty(TypeNameHandling = TypeNameHandling.All)] public DTOBase CommandDTO { get; set; } }
The question is, is there any other way than using the attribute to get the same result? I would prefer not to get attached to the NewtonSoft library and json serialization, in particular at the class level. Is there a way to specify some parameters in the Serialize / Deserialize methods of the library in general to get the same result?
source share