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

Change Newtonsoft.Json to System.Text.Json #112

Open
alexsaare opened this issue Dec 15, 2020 · 4 comments
Open

Change Newtonsoft.Json to System.Text.Json #112

alexsaare opened this issue Dec 15, 2020 · 4 comments

Comments

@alexsaare
Copy link

Would it be possible to change Newtonsoft.Json to System.Text.Json? There's performance benefits, it's lighter weight and it keeps the code native to Microsoft.

@snakefoot
Copy link
Contributor

snakefoot commented May 12, 2021

Yes but there are different side-effects:

  • System.Text.Json doesn't implement reference loop protection.
  • System.Text.Json doesn't render double zero as 0.0 but as 0 (Can give funny datatype-guessing issue when indexing)
  • System.Text.Json must be configured correctly to handle double.NaN and double.Infinity
  • System.Text.Json doesn't render fields by default (can be forced on)
  • System.Text.Json doesn't recognize the class-attributes from Newtonsoft.Json (for guiding serialization)
  • System.Text.Json carries a lot of new dependencies for .NetFramework, and those can be annoying because of strong-version issues.

See also: https://docs.microsoft.com/en-us/dotnet/standard/serialization/system-text-json-migrate-from-newtonsoft-how-to?pivots=dotnet-5-0

@alexsaare
Copy link
Author

Thanks for the response. I agree it's a change that requires thought and good communication.

There are many differences in behaviour however, they are not, IMO, a reason to keep the dependency given that most of them can be controlled with configuration and extension points such as JsonConverter<T>s.

ReferenceLoopHandling would be my only concern for this library and even then, to differ from the System.Text.Json implementation it's a setting which has to be explicitly set to Ignore (which this library does not do by default and I don't believe can be set via LogglyClient - please correct me if i'm wrong).

@snakefoot
Copy link
Contributor

snakefoot commented May 13, 2021 via email

@alexsaare
Copy link
Author

alexsaare commented May 13, 2021

Agreed - for net45 (and netstandard 1.6) I would keep Newtonsoft and have a multi target build which uses System.Text.Json for anything netstandard2.0+.

My previous post was more about backward compatibility and reducing behavioural changes as much as possible to reduce the impact on consumers.

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

No branches or pull requests

2 participants