Skip to content
This repository was archived by the owner on May 16, 2022. It is now read-only.
This repository was archived by the owner on May 16, 2022. It is now read-only.

AllowPrivateWithExcludeNull not deserializing private/protected member #28

@Tornhoof

Description

@Tornhoof

Hi,
StandardResolver.AllowPrivateExcludeNull does not properly deserialize private/protected members, StandardResolver.AllowPrivate works.

In the repro below input.Id is the default value

Repro:

namespace AllowPrivate
{
    class Program
    {
        static void Main(string[] args)
        {
            MyTest t = new MyTest();
            t.SetId(Guid.NewGuid());

            var output = JsonSerializer.ToJsonString(t, StandardResolver.AllowPrivateExcludeNull);
            var input = JsonSerializer.Deserialize<MyTest>(output, StandardResolver.AllowPrivateExcludeNull);
            Debug.Assert(t.Id == input.Id);
        }
    }

    public abstract class TestBase
    {
        public Guid Id { get; protected set; }
    }

    public class MyTest : TestBase
    {
        public void SetId(Guid id)
        {
            Id = id;
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions