In a POST handler task CE, the following code yields the error message in the title of this issue:
let! body = ctx.BindJsonAsync<NewCommentBody>()
However, by instead following the lead of BindXmlAsync's implementation, the following code works perfectly:
let serializer = ctx.GetJsonSerializer()
let! bodyText = ctx.ReadBodyFromRequestAsync()
let body = serializer.Deserialize<NewCommentBody> bodyText;
You can compare the implementations of BindJsonAsync and BindXmlAsync here: https://github.com/giraffe-fsharp/Giraffe/blob/master/src/Giraffe/ModelBinding.fs#L241
I've managed to recreate this, it looks like we would need Json.NET to add a DeserializeAsync entry point (they have async readers already) https://github.com/JamesNK/Newtonsoft.Json/issues/1193
Microsoft are also bringing a new fast and async library for working with JSON which would be a good idea to offer too. I'm happy to work on this when it matures.
Should not this be working fine with Utf8JsonSerializer ?
Out in 4.0.0
Most helpful comment
I've managed to recreate this, it looks like we would need Json.NET to add a
DeserializeAsyncentry point (they have async readers already) https://github.com/JamesNK/Newtonsoft.Json/issues/1193Microsoft are also bringing a new fast and async library for working with JSON which would be a good idea to offer too. I'm happy to work on this when it matures.