Skip to content

System.Text.Json causes duplicate fields for overridden members #112967

Closed
@KubaZ2

Description

@KubaZ2

Description

Happens for source generator based serialization as well (tested only with .NET 8).

Reproduction Steps

using System.Text.Json;
using System.Text.Json.Serialization;

JsonSerializer.Serialize(Console.OpenStandardOutput(), new B());

abstract class A
{
    [JsonPropertyName("x")]
    public abstract int I { get; }
}

class B : A
{
    public override int I => 10;
}

Expected behavior

{"x":10}

Actual behavior

{"I":10,"x":10}

Regression?

No response

Known Workarounds

Using the JsonPropertyNameAttribute on the overriding member.

Configuration

.NET 8 and 9

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions