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

JsonPropertyName is not inherited from abstract property #98663

Closed
Prochy opened this issue Feb 19, 2024 · 2 comments
Closed

JsonPropertyName is not inherited from abstract property #98663

Prochy opened this issue Feb 19, 2024 · 2 comments

Comments

@Prochy
Copy link

Prochy commented Feb 19, 2024

Description

An abstract property that has defined JsonPropertyName attribute is not inherited in a child class.

Reproduction Steps

public abstract class AbstractClass
{
    [JsonPropertyName("propertyname")]
    public abstract string PropertyName { get; }
}

public class Sample : AbstractClass
{
    public override string PropertyName => "PropertyValue";
}

internal class Program
{
    static void Main(string[] args)
    {
        var sample = new Sample();
        Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(sample));
    }
}

Expected behavior

{"propertyname":"PropertyValue"}

Actual behavior

{"PropertyName":"PropertyValue","propertyname":"PropertyValue"}

Regression?

No response

Known Workarounds

Define JsonPropertyName on the derived class.

Configuration

Windows: 19045.3930
.NET: 8.0.2
Console application
System.Text.Json: 8.0.2

Other information

In my opinion, the possible workaround produce unwanted that should be cover by .NET library and this should be fixed in the library itself and not by the workaround.

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

ghost commented Feb 19, 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

An abstract property that has defined JsonPropertyName attribute is not inherited in a child class.

Reproduction Steps

public abstract class AbstractClass
{
    [JsonPropertyName("propertyname")]
    public abstract string PropertyName { get; }
}

public class Sample : AbstractClass
{
    public override string PropertyName => "PropertyValue";
}

internal class Program
{
    static void Main(string[] args)
    {
        var sample = new Sample();
        Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(sample));
    }
}

Expected behavior

{"propertyname":"PropertyValue"}

Actual behavior

{"PropertyName":"PropertyValue","propertyname":"PropertyValue"}

Regression?

No response

Known Workarounds

Define JsonPropertyName on the derived class.

Configuration

No response

Other information

In my opinion, the possible workaround produce unwanted that should be cover by .NET library and this should be fixed in the library itself and not by the workaround.

Author: Prochy
Assignees: -
Labels:

area-System.Text.Json

Milestone: -

@eiriktsarpalis
Copy link
Member

Duplicate of #51165 (comment) and tracked by #73255

@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Feb 19, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Mar 21, 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