fsprojects / FSharp.Json

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

Add Thoth.Json #14

Closed MangelMaxime closed 5 years ago

vsapronov commented 5 years ago

Hi @MangelMaxime I have evaluated your Thoth.Json specifically Thoth.Json.Net. I have to say it's the best Newtonsoft.Json for F# adoption I have seen so far. I couldn't find any issues with null-safety that I spotted in other Newtonsoft-based solutions. The one thing I can complain is single case union types: https://vsapronov.github.io/FSharp.Json/unions.html#Single-case-union. And another minor issue: lack of customization of union record representation, like: "case": { value } or "key":"case", "value": { value }.

bartelink commented 5 years ago

For multi-case union, https://github.com/jet/Jet.ConfluentKafka.FSharp has an impl and tests that may be worth grabbing

MangelMaxime commented 5 years ago

Hello @vsapronov really happy that you like Thoth.Json :)

You can always define a manual decoder/encoder and have 100% control over the JSON representation.

But it's true that if you use "Auto decoder/encoder" then you are a bit more limited.

In version 3 of Thoth.Json we are adding the possibility to extend and override the behaviour for a given type. Documentation.

For example, auto decoders in Thoth.Json weren't supporting classes (except special cases) but with v3 you can now have classes support.

vsapronov commented 5 years ago

As a side conversation: What do you think about Newtonsoft as a core of your library? What are advantages? What are disadvantages? Any plans to use something else inside of Thoth.Json.Net? I have my opinions on these but interested to know other experiences from devs who went by similar path as I did.

By the way, I'm speaking about Json (de)serialization at F# eXchange in London this week. I would like to mention Thoth.Json for sure. Anything I should pay attention to specifically? I know Fable is a killer feature. Anything else?

MangelMaxime commented 5 years ago

@vsapronov Cool we will be able to meet their :) I am attending F# Exchange.

What do you think about Newtonsoft as a core of your library? What are advantages? What are disadvantages?

Well, what I don't like about Newtonsoft, in general, is auto serialization but I don't use it in Thoth.Json.Net as I am working at the JToken level. However, Newtonsoft still tries to interpret the JSON value. So for example, if you pass it a string and it detects the string as valid DateTime format it will give you a DateTime and I find it really annoying.

I am using Thoth.Json only in my project and made Thoth.Json.Net only because people asked support for it so I don't have much experience to share about it.

I am indeed planning in version 4 of Thoth.Json to rewrite the core of the library in order to make it easier to share the code between Fable and .Net/NetCore runtime. At the moment, people need to use compiler directive and it is not really friendly.

So the idea is to make Thoth.Json(.Core) JSON library agnostic and so people will be able to use Newtonsoft, standard JavaScript API, their own parser, etc.

Any plans to use something else inside of Thoth.Json.Net?

If I am unable able to make coding sharing easy by using a standard contact then I will write my own JSON parser in F#. I saw someone wrote one in less than 100 lines I think so the same code will be executed on the server and client.

I first want to try keeping Newtonsoft, standard JavaScript API because I believe they should be more performant than a "naive" JSON parser.

I would like to mention Thoth.Json for sure. Anything I should pay attention to specifically? I know Fable is a killer feature. Anything else?

I don't really know how to choose between what I see as selling points for Thoth.Json so I will do a list and let you decide :)

The most important points for me:

Secondary?

I hope I have answered your questions. :)

bartelink commented 5 years ago

So for example, if you pass it a string and it detects the string as valid DateTime format it will give you a DateTime and I find it really annoying.

See https://github.com/JamesNK/Newtonsoft.Json/issues/862 - there is an "arguably" ill-chosen default that can be flipped to remove this behaviour

MangelMaxime commented 5 years ago

Indeed seems like a odd choices with not much justifications. Thanks you for the link, I will take a deeper look at it later and perhaps choose to disable the auto convert feature.:)