You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm not sure if this is a bug or by design, but while moving from JSON.NET to System.Text.Json I discovered the following behavior:
"JsonPropertyNames" are ignored on base classes.
class Program
{
static void Main(string[] args)
{
RealClass test = new RealClass();
// output will be "{"Link":"Foo"}"
// and not {"_LinkFromBaseClass":"Foo"}
Console.WriteLine(JsonSerializer.Serialize(test));
Console.WriteLine("Hello World!");
}
}
public abstract class SomeBaseClass
{
[JsonPropertyName("_LinkFromBaseClass")]
public virtual string Link { get; }
}
public class RealClass : SomeBaseClass
{
public RealClass()
{
}
public override string Link { get { return "Foo"; } }
}
Is this "by design"? Currently we just put the "JsonPropertyName" attribute on all implementations for the baseclass, but it's quite easy to miss.
I also checked the JsonSerializerOptions, but didn't find anything useful, but maybe I miss something.
The text was updated successfully, but these errors were encountered:
I'm not sure if this is a bug or by design, but while moving from JSON.NET to System.Text.Json I discovered the following behavior:
"JsonPropertyNames" are ignored on base classes.
Is this "by design"? Currently we just put the "JsonPropertyName" attribute on all implementations for the baseclass, but it's quite easy to miss.
I also checked the JsonSerializerOptions, but didn't find anything useful, but maybe I miss something.
The text was updated successfully, but these errors were encountered: