Giraffe
Giraffe copied to clipboard
Make System.Text.Json the default JSON serializer
Description
This PR removes the Newtonsoft JSON serializer and promotes System.Text.Json as the default. I think System.Text.Json is the better choice these days. Among other things the default serializer
- Uses camel-case
- Serializes
Option
asvalue
ornull
- Supports ignoring
Option
ornull
values using the[<JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)>]
attribute
Any other specific behaviour should IMO be implemented by users, using attributes (e.g., [<JsonPropertyName("someName")>]
, [<JsonConverter(typeof<SomeCustomJsonConverter>)>]
), as there's no sensible defaults for most user-defined types.
How to test
Run tests and try to serialize/deserialize a JSON payload in a HttpHandler
.
Related issues
https://github.com/giraffe-fsharp/Giraffe/issues/481 https://github.com/giraffe-fsharp/Giraffe/issues/560 https://github.com/giraffe-fsharp/Giraffe/issues/451
@dustinmoris
Why are you removing Newtonsoft entirely? I can see maybe swapping the default but not outright removal.
It was my impression from discussion in #451 that it would be preferable to have it in a separate NuGet package and I agree with that sentiment. No reason to include the dependency by default if it's not going to be used. I also think System.Text.Json have become much better for F# with .NET 6/7 updates.
I also think this switch would get us closer to finally having a tryBindJson
function. I'll start working on that when/if this PR is approved.
I'll re-review this PR during this week. Thanks for the updates @esbenbjerre!
Thanks for the heads-up @TheAngryByrd! Since this PR is already open for a while, and we have many approvals, I'm going to merge it right now. Thanks for the contribution @esbenbjerre, great job!
JFYI – That turns out to be a massive breaking change to one of my applications which runs on Giraffe since 4 years. Not blaming anyone, but having some change log which makes things like that more explicit than the release page on GH would be nice ✌️
Hi @aspnetde, sorry for this breaking change. @abelbraaksma gave some suggestions at this issue on how to improve for future updates.
but having some change log which makes things like that more explicit than the release page on GH would be nice
Can you please expand this comment? What would you like to have found regarding this change?