`Thoth.Json.Net` cannot find Union case
Closed this issue · 4 comments
MangelMaxime commented
Issue by matthid
Thursday Oct 24, 2019 at 13:45 GMT
Originally opened as MangelMaxime/Thoth#175
open Fable.Core
open Thoth.Json.Net
[<StringEnum>]
type Test =
| Test1
| TEST2
[<EntryPoint>]
let main argv =
let t = TEST2
printfn "%A" t
let json = (Encode.Auto.toString(0, t))
printfn "json %A" json
let t2 : Test = Decode.Auto.unsafeFromString(json)
printfn "res %A" t2
0 // return an integer exit code
MangelMaxime commented
Comment by matthid
Thursday Oct 24, 2019 at 13:48 GMT
Interestingly not even Test1
works. Do I use it wrong?
MangelMaxime commented
Comment by MangelMaxime
Thursday Oct 24, 2019 at 13:50 GMT
Before your second message, I would have said it's due to how Fable works:
open Fable.Core
open Fable.Core.JsInterop
[<StringEnum>]
type Test =
| Test1
| TEST2
| [<CompiledName("TEST3")>] TEST3
JS.console.log(Test.Test1)
JS.console.log(Test.TEST2)
JS.console.log(Test.TEST3)
Output:
test1
tEST2
TEST3
MangelMaxime commented
Comment by matthid
Thursday Oct 24, 2019 at 13:56 GMT
Ok as discussed in gitter this is mainly due to [<StringEnum>]
MangelMaxime commented
Comment by MangelMaxime
Thursday Oct 24, 2019 at 14:07 GMT
Just so I remember, it's due to [<StringEnum>]
but still show that converting back and forth doesn't work on special cases. I need to cover them.