FSharp.Json icon indicating copy to clipboard operation
FSharp.Json copied to clipboard

Custom enum/union parsing/serialization

Open AntoineGagne opened this issue 5 years ago • 4 comments

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?

AntoineGagne avatar Jan 02 '20 23:01 AntoineGagne

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

vsapronov avatar Jan 18 '20 21:01 vsapronov

ping?

knocte avatar Mar 21 '20 10:03 knocte

Any changes here?

Reenuay avatar Aug 31 '21 20:08 Reenuay

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

bartelink avatar Sep 05 '21 07:09 bartelink