Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
YohDeadfall opened this issue Feb 11, 2020 · 0 comments · Fixed by #32107
Closed

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

YohDeadfall opened this issue Feb 11, 2020 · 0 comments · Fixed by #32107

Comments

@YohDeadfall
Copy link
Contributor

YohDeadfall commented Feb 11, 2020

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

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-System.Text.Json untriaged New issue has not been triaged by the area owner labels Feb 11, 2020
@ahsonkhan ahsonkhan added this to the 5.0 milestone Feb 19, 2020
@ahsonkhan ahsonkhan removed the untriaged New issue has not been triaged by the area owner label Feb 19, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants