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

Property duplication on overriding property with [JsonPropertyName] #97648

Closed
PSanetra opened this issue Jan 29, 2024 · 2 comments
Closed

Property duplication on overriding property with [JsonPropertyName] #97648

PSanetra opened this issue Jan 29, 2024 · 2 comments

Comments

@PSanetra
Copy link

Description

On serializing a derived class overridden properties may be duplicated if [JsonPropertyName] is assigned.

Reproduction Steps

Create the following classes:

public class VirtualProperty_TestClass
{
    public virtual string MyString { get; set; }
}

public class OverridePropertyNameInDerivedClass_TestClass : VirtualProperty_TestClass
{
    [JsonPropertyName("my_string")]
    public override string MyString { get; set; }
}

Then serialize an instance of OverridePropertyNameInDerivedClass_TestClass like this:

string serialized = JsonSerializer.Serialize(new OverridePropertyNameInDerivedClass_TestClass()
{
    MyString = "MyValue"
});
Assert.Equal(@"{""my_string"":""MyValue""}", serialized);

Expected behavior

This serialized string should be equal to {"my_string":"MyValue"}.

Actual behavior

This serialized string is equal to {"my_string":"MyValue","MyString":"MyValue"}.

Regression?

No response

Known Workarounds

No response

Configuration

.NET: 8.0.0
OS: Linux
Arch: x64
System.Text.Json: 8.0.0

Other information

Known affected code:
OpenIdConnectConfiguration.Issuer in Microsoft.IdentityModel.Protocols.OpenIdConnect is inherited from BaseConfguration.Issuer in Microsoft.IdentityModel.Tokens

Because of this issue serializing a OpenIdConnectConfiguration instance will create a json object with both an issuer and Issuer property. Some other properties like TokenEndpoint are affected, too.

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

ghost commented Jan 29, 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

Description

On serializing a derived class overridden properties may be duplicated if [JsonPropertyName] is assigned.

Reproduction Steps

Create the following classes:

public class VirtualProperty_TestClass
{
    public virtual string MyString { get; set; }
}

public class OverridePropertyNameInDerivedClass_TestClass : VirtualProperty_TestClass
{
    [JsonPropertyName("my_string")]
    public override string MyString { get; set; }
}

Then serialize an instance of OverridePropertyNameInDerivedClass_TestClass like this:

string serialized = JsonSerializer.Serialize(new OverridePropertyNameInDerivedClass_TestClass()
{
    MyString = "MyValue"
});
Assert.Equal(@"{""my_string"":""MyValue""}", serialized);

Expected behavior

This serialized string should be equal to {"my_string":"MyValue"}.

Actual behavior

This serialized string is equal to {"my_string":"MyValue","MyString":"MyValue"}.

Regression?

No response

Known Workarounds

No response

Configuration

.NET: 8.0.0
OS: Linux
Arch: x64
System.Text.Json: 8.0.0

Other information

Known affected code:
OpenIdConnectConfiguration.Issuer in Microsoft.IdentityModel.Protocols.OpenIdConnect is inherited from BaseConfguration.Issuer in Microsoft.IdentityModel.Tokens

Because of this issue serializing a OpenIdConnectConfiguration instance will create a json object with both an issuer and Issuer property. Some other properties like TokenEndpoint are affected, too.

Author: PSanetra
Assignees: -
Labels:

area-System.Text.Json, untriaged

Milestone: -

@eiriktsarpalis
Copy link
Member

Appears to be a duplicate of #51165

@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Jan 29, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Feb 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants