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

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

Open object opened this issue 5 years ago • 2 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"}}]

object avatar Oct 02 '20 10:10 object

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

object avatar Oct 02 '20 13:10 object

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.

MangelMaxime avatar Oct 28 '20 18:10 MangelMaxime