-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
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
Unwrap the whole union into a record #157
Comments
Hello, is there any ways to achieve that without using |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have the following two types:
and I want the
exVar
to be serialized as follows, where the record field name indicates the field name of the case value, and another field that indicates the tag of the union:with
JsonUnionEncoding.AdjacentTag
I was only able to get the follows:And I can't figure out how to achieve what I want.
EDIT: I figured out how to do that:
and call
JsonSerializer.Serialize()
on instances of ExUnion instead of ExRecord.But I still feel that such pattern is a bit counterintuitive, since I want to represent a field in a record whose type is annotated by another field in the same record, on the same level. Wrapping that with a DU under the record feels like a more natural way to do that. Even worse, this reverse-wrapping won't work if I want to achieve the follows:
and serialize
exVar
into the follows:The text was updated successfully, but these errors were encountered: