Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promote System.Text.Json as default JSON serializer #563

Merged
merged 8 commits into from
May 18, 2024

Conversation

esbenbjerre
Copy link
Contributor

@esbenbjerre esbenbjerre commented Oct 14, 2023

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 as value or null
  • Supports ignoring Option or null 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

#481
#560
#451

@esbenbjerre esbenbjerre marked this pull request as draft October 14, 2023 19:44
@esbenbjerre esbenbjerre force-pushed the feat/deprecate-newtonsoft branch 2 times, most recently from be7abc7 to 341df1d Compare October 14, 2023 21:13
@esbenbjerre esbenbjerre marked this pull request as ready for review October 14, 2023 21:15
@esbenbjerre
Copy link
Contributor Author

@dustinmoris

@TheAngryByrd
Copy link
Member

Why are you removing Newtonsoft entirely? I can see maybe swapping the default but not outright removal.

@esbenbjerre
Copy link
Contributor Author

esbenbjerre commented Oct 15, 2023

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.

@esbenbjerre
Copy link
Contributor Author

esbenbjerre commented Oct 19, 2023

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.

DOCUMENTATION.md Show resolved Hide resolved
DOCUMENTATION.md Show resolved Hide resolved
@esbenbjerre esbenbjerre changed the title Make System.Text.Json the default JSON serializer Promote System.Text.Json as default JSON serializer May 3, 2024
@esbenbjerre esbenbjerre requested a review from 64J0 May 3, 2024 08:47
@64J0 64J0 changed the base branch from develop to master May 12, 2024 14:54
@esbenbjerre esbenbjerre requested a review from dbrattli May 13, 2024 10:45
Copy link
Contributor

@dbrattli dbrattli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work. Thanks for doing this!!

@64J0
Copy link
Member

64J0 commented May 14, 2024

I'll re-review this PR during this week. Thanks for the updates @esbenbjerre!

Copy link
Member

@TheAngryByrd TheAngryByrd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the work on this!


@64J0 I want to mention I think this should be considered as a major version bump. Swapping JSON serialization can be a drastic change and shouldn't be taken lightly. A major bump should be a big signal that something has changed. It should also be very loud and clear in release notes with migration links to STJ or how to put back the Newtonsoft serializer.

@64J0
Copy link
Member

64J0 commented May 18, 2024

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!

@64J0 64J0 merged commit 557a2a6 into giraffe-fsharp:master May 18, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants