Typed results (such as Created<T>) do not emit type discriminator from attribute-based polymorphic serialization introduced in .NET 7 #45357
Labels
old-area-web-frameworks-do-not-use
*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
Is there an existing issue for this?
Describe the bug
If I have a type hierarchy with two classes
A
andB
, whereB
is derived fromA
andA
containsJsonPolymorphic
andJsonDerivedType
annotations, and I then have a request delegate that returnedCreated<A>
, the serialized response does not contain the type discriminator property.Expected Behavior
I would expect the response to include the type discriminator property as described in the docs for polymorphic serialization.
However, it does not.
Steps To Reproduce
Exceptions (if any)
No response
.NET Version
7.0.100
Anything else?
I believe this is caused by the considerations discussed in #43894 and #41724 to support backwards-compatible polymorphic serialization. Presumably due to those changes, ultimately the serialization code from
Created<T>
callsJsonSerializer.Serialize
explicitly with the runtime type of the value passed toCreated<T>
. but the documentation for the type discriminator feature explicitly requires the base type to be used.The text was updated successfully, but these errors were encountered: