We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When deserializing a polymorphic type with TypeDiscriminatorPropertyName set to an existing Property name, that Property is no longer deserialized
TypeDiscriminatorPropertyName
[JsonPolymorphic(TypeDiscriminatorPropertyName = "event")] [JsonDerivedType(typeof(ChildEvent), "child")] public abstract class EventBase { [JsonPropertyName("timestamp")] public DateTimeOffset Timestamp { get; init; } [JsonPropertyName("event")] public string Event { get; set; } } public class ChildEvent : EventBase; var json = """ { "event": "child", "timestamp":"2024-05-20T12:36:10Z" } """; var obj = JsonSerializer.Derserialize<EventBase>(json); Console.WriteLine(obj.Event); // "" // obj.Event = null;
TypeDiscriminator Property is still deserialized
TypeDiscriminator Property is always null/default
No response
.NET 9.0.100-preview.3.24204.13 Arch Linux 6.8.9-arch1-1 x86-64
The text was updated successfully, but these errors were encountered:
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis See info in area-owners.md if you want to be subscribed.
Sorry, something went wrong.
Duplicate of #72170 (comment). The runtime type of a property cannot be used to influence the discriminator which is a type-level mapping.
No branches or pull requests
Description
When deserializing a polymorphic type with
TypeDiscriminatorPropertyName
set to an existing Property name, that Property is no longer deserializedReproduction Steps
Expected behavior
TypeDiscriminator Property is still deserialized
Actual behavior
TypeDiscriminator Property is always null/default
Regression?
No response
Known Workarounds
No response
Configuration
.NET 9.0.100-preview.3.24204.13
Arch Linux 6.8.9-arch1-1 x86-64
Other information
No response
The text was updated successfully, but these errors were encountered: