0

It seems that the System.Text.Json serializer doesn't take into account JsonIgnore attributes when executing - I get this exception:

System.NotSupportedException: 'The collection type 'System.Collections.Generic.Dictionary`2[System.Int32,Test.TestObject]' is not supported.'

when executing this code:

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

Documentation for the new serializer is a little sparse - am I doing something wrong?

Ahmad Ibrahim
  • 1,915
  • 2
  • 15
  • 32
Liam
  • 5,033
  • 2
  • 30
  • 39

1 Answers1

0

Just seen that this is a "feature" that is being addressed soon - https://github.com/dotnet/corefx/pull/40413

Liam
  • 5,033
  • 2
  • 30
  • 39