Skip to content

Add serializer support for IAsyncEnumerable #1569

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

Closed
steveharter opened this issue Sep 26, 2019 · 3 comments
Closed

Add serializer support for IAsyncEnumerable #1569

steveharter opened this issue Sep 26, 2019 · 3 comments
Assignees
Milestone

Comments

@steveharter
Copy link
Member

This is a placeholder to uptake the recent IAsyncEnumerable feature for the serializer.

This includes creating an enumerator class that that implements IAsyncEnumerable and accepts a Stream in its constructor (and others TBD) that contains the actual JSON which can be accessed asynchronously:

public class SerializerAsyncEnumerable<T> : IAsyncEnumerable<T>
{
    public SerializerAsyncEnumerable(Stream stream);
    public SerializerAsyncEnumerable(Stream stream, JsonSerializerOptions options);
...
}

and also likely exposed from the JsonSerializer static class:

public static class JsonSerializer
{
...
    public SerializerAsyncEnumerable<T> DeserializeEnumerableAsync(Stream stream);
    public SerializerAsyncEnumerable<T> DeserializeEnumerableAsync(Stream stream, JsonSerializerOptions options);
...
}

The implementation will leverage the same patterns as in the existing async methods which preserve the unprocessed data from the stream (since the stream just returns raw JSON which won't align with object instances) and the "state" for continuing object deserialization as new JSON is obtained.

@steveharter steveharter self-assigned this Sep 26, 2019
@stephentoub
Copy link
Member

This includes creating an enumerator class

I'm not understanding this. Why is a new public type needed? e.g. why isn't it:

public IAsyncEnumerable<T> DeserializeEnumerableAsync(Stream stream);

?

@steveharter
Copy link
Member Author

steveharter commented Sep 27, 2019

I'm not understanding this. Why is a new public type needed? e.g. why isn't it:

It's flagged as still "API needs work" meaning "needs discussion" :)

If SerializerAsyncEnumerable<T> is public it may be convenient to return that instead of just IAsyncEnumerable<T> especially if there is any interesting state to expose (e.g. options, the Stream?).

@ericstj ericstj transferred this issue from dotnet/corefx Jan 9, 2020
@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the untriaged New issue has not been triaged by the area owner label Jan 9, 2020
@ericstj ericstj added area-System.Text.Json and removed untriaged New issue has not been triaged by the area owner labels Jan 9, 2020
@ericstj ericstj added this to the 5.0 milestone Jan 9, 2020
@layomia
Copy link
Contributor

layomia commented Apr 14, 2020

Closing as dup of #1570.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants