<PackageReference Include="System.Text.Json" Version="7.0.4" />

JsonPolymorphicAttribute

public sealed class JsonPolymorphicAttribute : JsonAttribute
When placed on a type, indicates that the type should be serialized polymorphically.
public bool IgnoreUnrecognizedTypeDiscriminators { get; set; }

When set to true, instructs the deserializer to ignore any unrecognized type discriminator id's and reverts to the contract of the base type. Otherwise, it will fail the deserialization.

public string TypeDiscriminatorPropertyName { get; set; }

Gets or sets a custom type discriminator property name for the polymorhic type. Uses the default '$type' property name if left unset.

Gets or sets the behavior when serializing an undeclared derived runtime type.