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 causes duplicate fields for overridden members #112967

Closed
KubaZ2 opened this issue Feb 26, 2025 · 2 comments
Closed

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

KubaZ2 opened this issue Feb 26, 2025 · 2 comments

Comments

@KubaZ2
Copy link

KubaZ2 commented Feb 26, 2025

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

@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Feb 26, 2025
Copy link
Contributor

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

@eiriktsarpalis
Copy link
Member

Duplicate of #92780. See #92780 (comment) for possible workarounds.

@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants