restsharp / RestSharp

Simple REST and HTTP API Client for .NET
https://restsharp.dev
Apache License 2.0
9.52k stars 2.34k forks source link

Async serializer? #2165

Open b-maslennikov opened 5 months ago

b-maslennikov commented 5 months ago

Would it be possible to add support of async serializer?

System.Text.Json IAsyncEnumerable serialization If you want to serialize IAsyncEnumerable in net6+ app you need to use JsonSerializer.SerializeAsync() method IRestSerializer does not allow to await inside Serializer() as it's synchronious method. Temporary solution - using GetAwaiter().GetResult() - but this approach doesn't offer "true" async support

alexeyzimarev commented 5 months ago

Yes, I think it's a good idea

alexeyzimarev commented 4 weeks ago

I tried to do it but getting full advantage of async serialisation requires reconsidering the way serialisation works in general in RestSharp. For example, SerializeAsync and DeserializeAsync of JsonSerializer work with streams, and RestSharp works with strings. So, the whole thing needs to be converted to work with streams instead of strings.

Of course, it is trivial to change the signature for interfaces and all the implementations. Would this help?