JsonSerializer behaves not as expected when the specifc class is casted to something else
问题 Im trying to migrate from json.net to microsoft's json and found something that behaves very differently. Let's use this simplified example: public interface IName { string Name { get; set; } } public class Person : IName { public string Name { get; set; } public int Age { get; set; } } public void Foo() { IName p = new Person {Age = 4, Name = "Waldo"}; var s1 = System.Text.Json.JsonSerializer.Serialize(p); // --> {"Name":"Waldo"} var s2 = Newtonsoft.Json.JsonConvert.SerializeObject(p); // --