似乎System.Text.Json序列化程序在执行时没有考虑JsonIgnore属性-我得到了这个异常:
System.NotSupportedException: 'The collection type 'System.Collections.Generic.Dictionary`2[System.Int32,Test.TestObject]' is not supported.'
执行此代码时:
public class TestObject
{
public int Id { get; set; }
}
public class TestObjects : Dictionary<int, TestObject>
{ }
public class test
{
public int Id { get; set; }
public string Name { get; set; }
[JsonIgnore]
public TestObjects TestObjects { get; set; }
}
class Program
{
static async Task Main(string[] args)
{
var m = new test();
var s = JsonSerializer.Serialize(m);
Debugger.Break();
}
新序列化器的文档有点稀疏-我做错什么了吗?