JsonIgnore和不支持的集合对象

时间:2019-08-29 18:30:04

标签: .net-core system.text.json

似乎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();
}

新序列化器的文档有点稀疏-我做错什么了吗?

1 个答案:

答案 0 :(得分:0)

刚刚看到这是一个即将解决的“功能”-https://github.com/dotnet/corefx/pull/40413