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

System.Text.Json ignores properties that override the setter only. #96996

Open
Tracked by #73255
eiriktsarpalis opened this issue Jan 15, 2024 · 1 comment
Open
Tracked by #73255

Comments

@eiriktsarpalis
Copy link
Member

A bit of a rare corner case, but the serializer isn't currently handling properties that only override the setter:

using System.Text.Json;

string json = JsonSerializer.Serialize(new Derived { X = 42 });
Console.WriteLine(json); // {}

public class Base
{
    public virtual int X { get; set; }
}

public class Derived : Base
{
    public override int X { set => base.X = value; }
}

This is because the serializer only inspects the signature of the override, but it should instead try to honor the signature of the base definition. Impacts both reflection and source generated serializers.

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jan 15, 2024
@ghost
Copy link

ghost commented Jan 15, 2024

Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis
See info in area-owners.md if you want to be subscribed.

Issue Details

A bit of a rare corner case, but the serializer isn't currently handling properties that only override the setter:

using System.Text.Json;

string json = JsonSerializer.Serialize(new Derived { X = 42 });
Console.WriteLine(json); // {}

public class Base
{
    public virtual int X { get; set; }
}

public class Derived : Base
{
    public override int X { set => base.X = value; }
}

This is because the serializer only inspects the signature of the override, but it should instead try to honor the signature of the base definition. Impacts both reflection and source generated serializers.

Author: eiriktsarpalis
Assignees: -
Labels:

area-System.Text.Json

Milestone: -

@eiriktsarpalis eiriktsarpalis added enhancement Product code improvement that does NOT require public API changes/additions bug and removed untriaged New issue has not been triaged by the area owner enhancement Product code improvement that does NOT require public API changes/additions labels Jan 15, 2024
@eiriktsarpalis eiriktsarpalis added this to the Future milestone Jan 15, 2024
@eiriktsarpalis eiriktsarpalis changed the title System.Text.Json ignored properties that override the setter only. System.Text.Json ignores properties that override the setter only. Jan 15, 2024
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jan 21, 2024
@eiriktsarpalis eiriktsarpalis removed the in-pr There is an active PR which will close this issue when it is merged label Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant