-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
[API Proposal]: add overloads to support IAsyncEnumerable with source-gen #59268
Comments
Tagging subscribers to this area: @eiriktsarpalis, @layomia Issue DetailsBackground and motivationAdd overloads to support Once implemented, source-gen scenarios using should no longer throw API Proposalnamespace System.Text.Json
{
public static class JsonSerializer
{
+ public static System.Collections.Generic.IAsyncEnumerable<TValue?> DeserializeAsyncEnumerable<TValue>(System.IO.Stream utf8Json, System.Text.Json.Serialization.Metadata.JsonTypeInfo<TValue> jsonTypeInfo, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
}
}
namespace System.Text.Json.Serialization.Metadata
{
public static class JsonMetadataServices
{
+ public static System.Text.Json.Serialization.JsonConverter<T?> GetAsyncEnumerableConverter<T>(System.Text.Json.Serialization.Metadata.JsonTypeInfo<T> underlyingTypeInfo);
}
} API Usage// fast-path serialization will generate calls to serialize. For example on a property on a Foo POCO class:
private static void FooSerialize(global::System.Text.Json.Utf8JsonWriter writer, Foo value)
{
...
writer.WritePropertyName(PropName_MyAsyncEnumerable);
global::System.Text.Json.JsonSerializer.Serialize(writer, value.MyAsyncEnumerable, MySerializationContext.Default.MyAsyncEnumerable);
...
}
// and manual calls to deserialize are supported:
System.IO.Stream utf8Json = ...;
IAsyncEnumerable<MyAsyncEnumerable> value = JsonSerializer.DeserializeAsyncEnumerable(stream, MySerializationContext.Default.MyAsyncEnumerable); RisksNo response
|
@pranavkm / @davidfowl -- Would ASP.NET use this in .NET 7 if we included it in one of the later previews? If not, we're leaning toward punting this to Future. |
Exposing top-level methods for IAsyncEnumerable serialization is one thing, but for completeness we also need to consider exposing the IAsyncEnumerable converter in the JsonMetadataServices namespace to ensure parity in scenaria like the ones described in #58221 |
FWIW I don't think we would be able to support fast-path serialization for IAsyncEnumerable easily. It would require exposing a |
I've updated the OP, believe we can take this to API review now. |
Looks good as proposed namespace System.Text.Json
{
public partial static class JsonSerializer
{
// Existing
// public static IAsyncEnumerable<TValue?> DeserializeAsyncEnumerable<TValue>(Stream utf8Json, JsonSerializerOptions options, CancellationToken cancellationToken = default);
public static IAsyncEnumerable<TValue?> DeserializeAsyncEnumerable<TValue>(Stream utf8Json, JsonTypeInfo<TValue> jsonTypeInfo, CancellationToken cancellationToken = default);
}
}
namespace System.Text.Json.Serialization.Metadata
{
[EditorBrowsable(EditorBrowsableState.Never)]
public static class JsonMetadataServices
{
// Existing
// public static JsonTypeInfo<TCollection> CreateIEnumerableInfo<TCollection, TElement>(JsonSerializerOptions options, JsonCollectionInfoValues<TCollection> collectionInfo) where TCollection : IEnumerable<TElement>;
public static JsonTypeInfo<TAsyncEnumerable> CreateIAsyncEnumerableInfo<TAsyncEnumerable, TElement>(JsonSerializerOptions options, JsonCollectionInfoValues<TAsyncEnumerable> collectionInfo) where TAsyncEnumerable : IAsyncEnumerable<TElement>;
}
} |
Background and motivation
Add overloads to support
IAsyncEnumerable
with source-gen. See #58221 for more information.Once implemented, source-gen scenarios using should no longer throw
NotSupportedException
when usingIAsyncEnumerable<T>
.API Proposal
API Usage
Risks
No response
The text was updated successfully, but these errors were encountered: