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
Right now, when deserializing a union where each case is a record, it appears that we cannot have the discriminator property be part of the record definition itself. The library throws an exception saying that the field is missing from the JSON, even though it is indeed available.
Unhandled exception. System.Text.Json.JsonException: Missing field for record type Program+Employee: __typeName
at System.Text.Json.Serialization.JsonRecordConverter`1.ReadRestOfObject(Utf8JsonReader& reader, JsonSerializerOptions options, Boolean skipFirstRead)
at System.Text.Json.Serialization.JsonRecordConverter`1.System.Text.Json.Serialization.IRecordConverter.ReadRestOfObject(Utf8JsonReader& reader, JsonSerializerOptions options, Boolean skipFirstRead)
Expected
To be able to deserialize employeeJson as SearchResult and populate __typename with "Employee"
Actual
An exception is thrown
The text was updated successfully, but these errors were encountered:
I see, you want the "__typename" field to be used both as the tag for SearchResult and a field for Employee. It's not something I would have expected to be needed, but it's reasonable to expect it to work.
It's not something I would have expected to be needed, but it's reasonable to expect it to work.
It is required sometimes when working with Snowflaqe and configuring the serializer to use System.Text.Json. Right now, my workaround is to not generate the __typename field for the records but this isn't ideal when __typename is the only field that needs to be generated which is sometimes the case.
Description
Right now, when deserializing a union where each case is a record, it appears that we cannot have the discriminator property be part of the record definition itself. The library throws an exception saying that the field is missing from the JSON, even though it is indeed available.
Reproduction
Error
Expected
To be able to deserialize
employeeJson
asSearchResult
and populate__typename
with "Employee"Actual
An exception is thrown
The text was updated successfully, but these errors were encountered: