I'm using .NET 6 RC2.
using System.Text.Json;
using System.Text.Json.Serialization;
using Stream stream = Console.OpenStandardOutput();
Measurements data = new(DateTime.Now, GetValues(10));
await JsonSerializer.SerializeAsync<Measurements>(stream, data, JsonContext.Default.Measurements);
Console.WriteLine();
static async IAsyncEnumerable<int> GetValues(int n)
{
for (int i = 0; i < n; i++) yield return Random.Shared.Next(i);
}
internal record Measurements(DateTime time, IAsyncEnumerable<int> Values);
// Source generator definition
[JsonSerializable(typeof(Measurements))]
internal partial class JsonContext : JsonSerializerContext
{
}
This code produces the following result:
{"time":"2021-08-26T15:08:56.93747-07:00","Values":{}}
If I switch out the JsonSerializer call to the following, I get the following desired result.
await JsonSerializer.SerializeAsync<Measurements>(stream, data);
and
{"time":"2021-08-26T15:07:58.698976-07:00","Values":[0,0,0,1,0,3,1,3,0,1]}
Is this scenario unsupported or I'm doing something wrong?
I'm using .NET 6 RC2.
This code produces the following result:
{"time":"2021-08-26T15:08:56.93747-07:00","Values":{}}If I switch out the JsonSerializer call to the following, I get the following desired result.
and
{"time":"2021-08-26T15:07:58.698976-07:00","Values":[0,0,0,1,0,3,1,3,0,1]}Is this scenario unsupported or I'm doing something wrong?