Skip to content

Commit

Permalink
#517 final test fail with STJ now passing!
Browse files Browse the repository at this point in the history
  • Loading branch information
tmenier committed Jun 3, 2022
1 parent ac6b55e commit b081ce3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions Test/Flurl.Test/Http/TestingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -427,12 +427,12 @@ public async Task can_fake_cookies() {
// https://github.com/tmenier/Flurl/issues/175
[Test]
public async Task can_deserialize_default_response_more_than_once() {
var resp = await "http://www.api.com".GetJsonAsync();
var resp = await "http://www.api.com".GetJsonAsync<object>();
Assert.IsNull(resp);
// bug: couldn't deserialize here due to reading stream twice
resp = await "http://www.api.com".GetJsonAsync();
resp = await "http://www.api.com".GetJsonAsync<object>();
Assert.IsNull(resp);
resp = await "http://www.api.com".GetJsonAsync();
resp = await "http://www.api.com".GetJsonAsync<object>();
Assert.IsNull(resp);
}

Expand Down
5 changes: 3 additions & 2 deletions src/Flurl.Http/Configuration/DefaultJsonSerializer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using System.Security.Cryptography;
using System.Text.Json;

namespace Flurl.Http.Configuration
Expand Down Expand Up @@ -29,12 +30,12 @@ public DefaultJsonSerializer(JsonSerializerOptions options = null) {
/// Deserializes the specified JSON string to an object of type T.
/// </summary>
/// <param name="s">The JSON string to deserialize.</param>
public T Deserialize<T>(string s) => JsonSerializer.Deserialize<T>(s, _options);
public T Deserialize<T>(string s) => string.IsNullOrWhiteSpace(s) ? default : JsonSerializer.Deserialize<T>(s, _options);

/// <summary>
/// Deserializes the specified stream to an object of type T.
/// </summary>
/// <param name="stream">The stream to deserialize.</param>
public T Deserialize<T>(Stream stream) => JsonSerializer.Deserialize<T>(stream, _options);
public T Deserialize<T>(Stream stream) => stream.Length == 0 ? default : JsonSerializer.Deserialize<T>(stream, _options);
}
}

0 comments on commit b081ce3

Please sign in to comment.