fsprojects / FSharp.Json

F# JSON Reflection based serialization library
Apache License 2.0
226 stars 26 forks source link

Custom enum/union parsing/serialization #32

Open AntoineGagne opened 4 years ago

AntoineGagne commented 4 years ago

Hi, I want to serialize a type such as:

type State =
    | None
    | OverflowedState
    | RestartedState

type Main =
    { State: State
    }

to have the following JSON:

{
    "state": "<none|overflowed_state|restarted_state>"
}

I tried using transforms for this, but they don't seem to get called for enum/union values. Is there any way to do it?

vsapronov commented 4 years ago

I see the problem - I will take a look at this.

knocte commented 4 years ago

ping?

Reenuay commented 3 years ago

Any changes here?

bartelink commented 3 years ago

Can borrow scheme and some impl from https://github.com/eiriktsarpalis/TypeShape/blob/main/src/TypeShape/Applications/UnionContract.fs#L9