-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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 inheritance perserve the parent member #51165
Comments
Tagging subscribers to this area: @eiriktsarpalis, @layomia Issue DetailsWhen JsonPropertyName is applied to a sub-class override member, the original name in the parent class is preserved in the output of JsonSerializer.Serialize, as a result, that's two JSON field. I don't think this is by design? Description
Configuration
|
That seems like a bug to me. FWIW I can reproduce the same behaviour when I create this combination: public abstract class Person
{
[JsonPropertyName("StudentName")]
public virtual string Name { get; }
}
public class Student : Person
{
public override string Name => "Bob";
} but the issue goes away when I remove the |
@eiriktsarpalis I can have a look. Even if it's a bug - fixing this would be a breaking change. |
Triage - this isn't a regression from .NET 5.0 and I think it's a bit too late in the 6.0 wave to introduce a breaking change like this. We should consider in .NET 7.0. |
Is there any workaround? |
Another bug related to this issue.
Results in 2 properties:
|
Unfortunately we won't have time to address this in 7.0 but contract customization can be used to workaround this. Moving to 8.0 in the meantime |
For those who may be looking for a work around until this can be addressed. You can make use of a dummy property:
|
Just ran into this as well. I was hoping to avoid contract customization as it feels a bit heavy for this; might try the workaround posted above instead. Would be nice if it worked out of the box though |
This is causing source generation to generate invalid code when it interacts with |
When JsonPropertyName is applied to a sub-class override member, the original name in the parent class is preserved in the output of JsonSerializer.Serialize, as a result, that's two JSON field. I don't think this is by design?
Description
{"StudentName":"Alice"}
{"StudentName":"Alice","Name":"Alice"}
Configuration
.NET 5.0.2
Windows 10 2004
X64
The text was updated successfully, but these errors were encountered: