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
For polymorphic scenarios, the new modifier does not always work with JsonIgnore. This affects both the reflection-based serializer and the source-gen serializer. See also #58985 (comment)
The semantics of the new modifier need to be documented and deterministic. For example, when [JsonIgnore] is applied to a derived type's property that has new and [JsonIgnore], does the base class property (which is a different property / has its own vtable slot) get serialized and deserialized?
Also verification is need when [JsonIgnore] and new are used along other attributes including [JsonPropertyOrder] on a derived type's property. The serializer should used the [JsonPropertyOrder] on the property that is actually serialized, and not the one that is ignored.
Test case failure
stringjson= JsonSerializer.Serialize(new ConcreteDerivedClass());// Throws System.ArgumentException: 'An item with the same key has already been added. Key: Ignored_New_Property' publicclassConcreteDerivedClass:AbstractBaseClass{[JsonIgnore]publicnewintIgnored_New_Property{get;set;}=1;// Also test with making this new slot method virtual}publicabstractclassAbstractBaseClass{[JsonIgnore]publicintIgnored_New_Property{get;set;}=2;}
For polymorphic scenarios, the new modifier does not always work with JsonIgnore. This affects both the reflection-based serializer and the source-gen serializer.
stringjson= JsonSerializer.Serialize(new ConcreteDerivedClass());// Throws System.ArgumentException: 'An item with the same key has already been added. Key: Ignored_New_Property' publicclassConcreteDerivedClass:AbstractBaseClass{[JsonIgnore]publicnewintIgnored_New_Property{get;set;}=1;}publicabstractclassAbstractBaseClass{[JsonIgnore]publicintIgnored_New_Property{get;set;}=2;}
For polymorphic scenarios, the
new
modifier does not always work withJsonIgnore
. This affects both the reflection-based serializer and the source-gen serializer. See also #58985 (comment)The semantics of the
new
modifier need to be documented and deterministic. For example, when[JsonIgnore]
is applied to a derived type's property that hasnew
and[JsonIgnore]
, does the base class property (which is a different property / has its own vtable slot) get serialized and deserialized?Also verification is need when
[JsonIgnore]
andnew
are used along other attributes including[JsonPropertyOrder]
on a derived type's property. The serializer should used the[JsonPropertyOrder]
on the property that is actually serialized, and not the one that is ignored.Test case failure
Test case success 1 (serialize)
Test case success 2 (serialize)
Test case success 3 (deserialize)
Test case success 4 (deserialize)
The text was updated successfully, but these errors were encountered: