Skip to content

Conversation

@dtymakhov
Copy link

I added a new AsValue to the UnionMode. This will be useful when the field can be one of a type, such as a int or a string. But this cannot be deserialised.

For example:

  [<JsonUnion(Mode = UnionMode.AsValue)>]
    type AsValueUnion =
    | StringCase of string
    | IntCase of int

    type RecordWithAsValueUnion = {
        StringValue : AsValueUnion
        IntValue : AsValueUnion
    }

  let record = { StringValue = StringCase "String"; IntValue = IntCase 1 }

will be serialised like a {"StringValue":"String","IntValue":1}

@dtymakhov dtymakhov closed this by deleting the head repository Nov 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants