Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,7 @@ public static partial class HttpClientJsonExtensions
JsonSerializerOptions? options,
CancellationToken cancellationToken)
{
options ??= JsonSerializerOptions.Default;
options.MakeReadOnly();

var jsonTypeInfo = (JsonTypeInfo<TValue>)options.GetTypeInfo(typeof(TValue));
var jsonTypeInfo = (JsonTypeInfo<TValue>)JsonHelpers.GetJsonTypeInfo(typeof(TValue), options);

return FromJsonStreamAsyncCore(client, requestUri, jsonTypeInfo, cancellationToken);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,43 @@ public async Task GetFromJsonAsAsyncEnumerable_EnforcesTimeoutOnInitialRequest()
await Task.Delay(TimeSpan.FromMilliseconds(10));
}
}

[Fact]
public async Task GetFromJsonAsAsyncEnumerable_SerializerUsesCamelCase()
{
using var client = new HttpClient(new CustomResponseHandler((r, c) =>
{
string json = """[{"value":1},{"value":2}]""";
HttpResponseMessage response = new()
{
Content = new StringContent(json)
};
return Task.FromResult(response);
}));

await foreach (var m in client.GetFromJsonAsAsyncEnumerable<TestModel>("http://dummyUrl"))
{
Assert.True(m.Value > 0);
}
}

[Fact]
public async Task GetFromJsonAsAsyncEnumerable_CustomSerializerOptions()
{
using var client = new HttpClient(new CustomResponseHandler((r, c) =>
{
string json = """[{"Value":1},{"Value":2}]""";
HttpResponseMessage response = new()
{
Content = new StringContent(json)
};
return Task.FromResult(response);
}));
await foreach (var m in client.GetFromJsonAsAsyncEnumerable<TestModel>("http://dummyUrl", JsonSerializerOptions.Default))
{
Assert.True(m.Value > 0);
}
}
}
}

Expand All @@ -593,3 +630,8 @@ public CustomResponseHandler(
protected override Task<HttpResponseMessage> SendAsync(
HttpRequestMessage request, CancellationToken cancellationToken) => _func(request, cancellationToken);
}

file sealed class TestModel
{
public int Value { get; set; }
}