Skip to content

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

Closed

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: {}

Activity

  1. added this to the 5.0 milestone on Feb 19, 2020
  2. removed
    untriagedNew issue has not been triaged by the area owner
    on Feb 19, 2020
  3. ghost locked as resolved and limited conversation to collaborators on Dec 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions