Skip to content

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

Open

Description

@eiriktsarpalis

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.

Activity

  1. ghost added
    untriaged
    on Jan 15, 2024
  2. added
    enhancement
    and removed
    untriaged
    enhancement
    on Jan 15, 2024
  3. added this to the Future milestone on Jan 15, 2024
  4. changed the title [-]System.Text.Json ignored properties that override the setter only.[/-] [+]System.Text.Json ignores properties that override the setter only.[/+] on Jan 15, 2024
  5. ghost added
    in-pr
    on Jan 21, 2024
  6. removed
    in-pr
    on Jul 16, 2024
  7. added
    in-pr
    on Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Text.Jsonbugin-pr

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions