I have a json that I am deserializing by using NewtonSoftJson Json library as shown below:
public async Task InvokeAsync(HttpContext httpContext, ISchema schema)
{
...
var request = Deserialize<GraphQLRequest>(httpContext.Request.Body);
....
}
public static T Deserialize<T>(Stream s)
{
using (var reader = new StreamReader(s))
using (var jsonReader = new JsonTextReader(reader))
{
var ser = new JsonSerializer();
return ser.Deserialize<T>(jsonReader);
}
}
Now I am trying to use System.Text.Json
library to deserialize asynchronously so I read their docs and they do have DeserializeAsync
method which I can use but when I replace content of above method like below then I get compilation error -
public static T Deserialize<T>(Stream s)
{
return JsonSerializer.DeserializeAsync<GraphQLRequest>(s, new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true
}
);
}
Error I get is -
Cannot convert expression type 'System.Threading.Tasks.ValueTask<App.Api.Kestrel.GraphQLRequest?>' to return type 'T'
I am new to dotnet world so kinda confuse what is wrong I am doing here?