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.JsonSerializer.Serialize ignores JsonPropertyName on abstract properties #39790

Closed
vsfeedback opened this issue Jul 22, 2020 · 1 comment

Comments

@vsfeedback
Copy link

This issue has been moved from a ticket on Developer Community.


Consider the following code:

abstract class A
{
    [JsonPropertyName("id")]
    public abstract string Id { get; }
}

class B : A
{
public override string Id => "Value";
}

When serializing an instance of type B:

Expected: JsonPropertyName to affect inheriting class

{"id":"Value"}

Actual: JsonPropertyName has no effect

{"Id":"Value"}

Note: This behavior differs from the one in Newtonsoft.Json and in my opinion is more error prone.


Original Comments

Feedback Bot on 7/20/2020, 03:33 AM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.


Original Solutions

(no solutions)

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-System.Text.Json untriaged New issue has not been triaged by the area owner labels Jul 22, 2020
@layomia layomia removed the untriaged New issue has not been triaged by the area owner label Jul 23, 2020
@layomia layomia added this to the 5.0.0 milestone Jul 23, 2020
@layomia
Copy link
Contributor

layomia commented Jul 23, 2020

This is known/by design. Properties cannot inherit System.Text.Json attributes. The attributes need to be placed on each (de)serializable override.

@layomia layomia closed this as completed Jul 23, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 8, 2020
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

3 participants