Open
Description
Description
System.Text.Json cannot deserialize JSON which contains the $schema
metadata property.
Reproduction Steps
From #79059 (comment):
[JsonDerivedType(typeof(DerivedType), typeDiscriminator: nameof(DerivedType))]
public abstract class BaseType
{
}
public sealed class DerivedType : BaseType
{
}
internal class Program
{
static void Main()
{
var text =
"""
{
"$type": "DerivedType",
"$schema": "http://example.org/myschema.json",
}
""";
var baseObj = JsonSerializer.Deserialize<BaseType>(text);
}
}
Expected behavior
Deserialization should succeed without throwing an exception.
Actual behavior
JsonSerializer.Deserialize
throws an exception: System.Text.Json.JsonException: Properties that start with '$' are not allowed in types that support metadata. Either escape the character or disable reference preservation and polymorphic deserialization.
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response