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 using IAsyncEnumerable<T>.
API Proposal
namespace System.Text.Json
{
public static class JsonSerializer
{
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
{
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> {}
}
}
API Usage
JsonSerializer.Serialize(new MyPoco { Data = ... }, MyContext.MyPoco); // Currently not supported
[JsonSerializable(typeof(typeof(MyPoco))]
public class MyContext : JsonSerializerContext {}
public class MyPoco
{
public IAsyncEnumerable<int> Data { get; set; }
}
Risks
No response
Background and motivation
Add overloads to support
IAsyncEnumerablewith source-gen. See #58221 for more information.Once implemented, source-gen scenarios using should no longer throw
NotSupportedExceptionwhen usingIAsyncEnumerable<T>.API Proposal
namespace System.Text.Json { public static class JsonSerializer { 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 { 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> {} } }API Usage
Risks
No response