Open Sonic198 opened 6 months ago
@Tornhoof but how that would be usable in that case?
Are you aware of https://learn.microsoft.com/en-us/dotnet/api/system.text.json.jsonserializer.deserializeasyncenumerable ?
It depends on the exact structure of your json response. If your array is nested inside another object it won't help.
The reasoning for only root-level IAsyncEnumerable support is here https://github.com/dotnet/runtime/issues/1570#issuecomment-804355005
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis See info in area-owners.md if you want to be subscribed.
It depends on the exact structure of your json response. If your array is nested inside another object it won't help.
The reasoning for only root-level IAsyncEnumerable support is here #1570 (comment)
Yeah so as you can see in first post I unfortunately gets one object with nested array of objects in it so I guess there is no easy way of utilizing IAsyncEnumerable to deserialize those data.
This is a known restriction of the DeserializeAsyncEnumerable
methods. In principle it should be possible to expose new overloads that additionally accept a JSON path value pinpointing an entry point for the streamed array, in your example:
JsonSerializer.DeserializeAsyncEnumerable<Event>(utf8Stream, path: "$.eventList");
We would need to add corresponding overloads to System.Net.Http.Json
as well.
Hello, I'm using
HttpClient
to integrate with an API which returns data in following formatIt is possible to have hundreds or even thousands of events inside
eventList
so since now we can useReadFromJsonAsAsyncEnumerable<TValue>
I was wondering if it would be possible to somehow iterate through that objects ineventList
array without a need of loading all of them into memory?