Skip to content

JSON serializer ignores a base public property hidden by a new slot private one #32106

@YohDeadfall

Description

@YohDeadfall

The following code should serialize the MyString property of ClassWithPublicProperty, but it doesn't happen because GetProprties(BindingFlags.Instance | BindingFlags.Public) doesn't return base properties which are hidden by a new slot member.

var obj = new ClassWithNewSlotPrivateProperty();
string json = JsonSerializer.Serialize(obj);
public class ClassWithPublicProperty
{
    public string MyString { get; set; } = "DefaultValue";
}

public class ClassWithNewSlotPrivateProperty : ClassWithPublicProperty
{
    private new string MyString { get; set; } = "NewDefaultValue";
}

Expected: {"MyString":"DefaultValue"}
Actual: {}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions