question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for System.Text.Json

See original GitHub issue

The built-in JSON serializer uses Newtonsoft.Json. But in ASP.NET Core 3.0, the default serializer is System.Text.Json. It would be nice if Tiny.RestClient supported it, because:

  • It has better performance than Newtonsoft.Json
  • If the rest of the application uses System.Text.Json, it would be better if everything used it. It would be more consistent, and would allow reuse of the same settings, converters, etc.

It’s easy enough to implement a IFormatter that uses System.Text.Json, but there’s a bit of an impedance mismatch between the IFormatter and System.Text.Json APIs… IFormatter only has synchronous methods that take a Stream. But System.Text.Json doesn’t have synchronous methods that accept a stream, only async ones. And they return a ValueTask, so we can’t just use .Result. Maybe the solution would be to add a IAsyncFormatter interface. If the formatter implements it, use the async methods, if not, use the sync methods.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jgiacominicommented, Oct 31, 2022

Hello guys,

I have a PR ready which remove NewtownSoft.Json and make library compatible with System.Text.Json.

I will release this week the version 2.0 of the library

I am also writing benchmarks to try to remove unecessary allocations.

1reaction
thomaslevesquecommented, Apr 2, 2020

being able to change serializer would be great

It’s already possible today, by providing your own implementation of IFormatter. Anyway, maybe Newtonsoft.Json support could be provided as a separate package.

also be able to use protobuf since the GRPC Protocol is increasingly used

Yes, but GRPC is not ReST…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Migrate from Newtonsoft.Json to System.Text.Json - .NET
Supported by built-in functionality. Getting similar behavior from System.Text.Json may require the use of an attribute or global option.
Read more >
System.Text.Json 7.0.3
Provides high-performance and low-allocating types that serialize objects to JavaScript Object Notation (JSON) text and deserialize JSON text to objects, ...
Read more >
Introduction to System.Text.Json Through Examples
System.Text.Json library helps us handle JSON in ASP.NET applications. It comes integrated with the framework and it's simple and easy to ...
Read more >
Using System.Text.Json to do polymorphic Json conversion in ...
Here are a few helpful converters - for example for doing polymorphic conversion.
Read more >
Should you use Newtonsoft.Json or System.Text. ...
James Newton King works on both of them. System.text.json uses Spans under the covers and is apparently dozens of times faster, but Span...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found