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

[feature request] Support System.Text.Json as alternative to Newtonsoft.Json #20

Open
Tyler-IN opened this issue May 28, 2024 · 1 comment

Comments

@Tyler-IN
Copy link
Contributor

Tyler-IN commented May 28, 2024

Instead of this,

var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

return
  global::Newtonsoft.Json.JsonConvert.DeserializeObject<...>(content) ??
  throw new global::System.InvalidOperationException("Response deserialization failed for

Always read as a stream async and feed into JsonSerializer.DeserializeAsync<TValue>.

This avoids multiple copy and conversion operations and continues the async pattern.
(Buffer construction [eg. stream buffer grown to fit then copied to single solid buffer], UTF-16 char copying conversion into string, then deserialization converting UTF-16 into various types.)

This would add a dependency on MS's System.Text.Json package.
Support goes down to .NET Standard 2.0.

@HavenDV
Copy link
Owner

HavenDV commented May 28, 2024

yes, I agree with this. I didn't implement this as the default solution because the current solution allows for much easier debugging when the server sends something other than the expected json. in this case, an exception is completely uninformative.
Ideally I would implement your suggestion, but so that there are no problems with debugging

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