-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Open
Labels
Milestone
Description
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
abstract class Person
{
public abstract string Name { get; set; }
}
class Student : Person
{
[JsonPropertyName("StudentName")]
public override string Name { get; set; }
}
var json = JsonSerializer.Serialize(new Student() { Name = "Alice" });- Expected:
{"StudentName":"Alice"} - Actual:
{"StudentName":"Alice","Name":"Alice"}
Configuration
- Which version of .NET is the code running on?
.NET 5.0.2 - What OS and version, and what distro if applicable?
Windows 10 2004 - What is the architecture (x64, x86, ARM, ARM64)?
X64
fudiwei, IGx89, leoshusar, tanveerbadar, superkartoffel and 3 more