thoth-org / Thoth.Json

Library for working with JSON in a type safe manner, this libs is targeting Fable

Home Page:https://thoth-org.github.io/Thoth.Json/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Auto-encoders in Thoth.Json and Thoth.Json.Net generate incompatible JSON for distriminated unions

object opened this issue · comments

I reproduced this using versions of Thoth.Json 4.0 and Thoth.Json.Net 4.1.

This is an example of a JSON generated using Decode.Auto from a Fable app (Thoth.Json):

"Customer":["Verified",{"comparer":{},"tree":["MapOne","CustomerIdentity",{"Id":1,"PhoneNumber":"12345678"}]}]

Thoth.Json.Net fails to decode this string because it doesn't expect comparer node. If I serialize the same data using Thoth.Json.Net, it works fine:

"Customer":["Verified",{"CustomerIdentity":{"Id":1,"PhoneNumber":"12345678"}}]

Out of curiosity: is "comparer" element used in some scenarios? Looks like Thoth.Json.Giraffe/Thoth.Json.Net manage fine without it.

Hello @object sorry for the delay

This is bug in Thoth.Json (Fable version) which kind of "stringify" the whole instance of a map.

I suppose you DUs looks similar to Verifier of Map<.., ...>

If you look at the instance of your map in memory you will an object with comparer and tree property.

As a workaround you can use manual decoder for now.