我正在使用NewtonSoft
JSON.NET库来序列化以下类,其中DTOBase可以保存派生实例.
public class Command { public DTOBase CommandDTO { get; set; } }
根据this article,您需要包含JsonProperty属性,以便派生实例正确反序列化
public class Command { [JsonProperty(TypeNameHandling = TypeNameHandling.All)] public DTOBase CommandDTO { get; set; } }
问题是除了使用属性获得相同的结果之外是否还有其他方法?我更愿意不与NewtonSoft库和json序列化相结合,特别是在类级别.有没有办法在库的Serialize / Deserialize方法上指定一些设置以获得相同的结果?