Can not deserialize API response of type Results<TResult1,TResult2>

43 Views Asked by At

I have API with endpoint like public class SampleEndpoint: Endpoint<SampleEndpointQuery, Results<Ok<SampleResponse>, NotFound>>

And everything works fine via swagger or Postman, but now I am creating client that need to serialize this response. I am using Refit for creating a API client.

Task<Results<Ok<SampleResponse>, NotFound>> GetSampleResponse();

And the problem comes from deserialization of this object:

"Results<Ok, NotFound>" `Deserialization of types without a parameterless constructor, a singular parameterized constructor, or a parameterized constructor annotated with 'JsonConstructorAttribute' is not supported. Type 'Microsoft.AspNetCore.Http.HttpResults.Results`2[Microsoft.AspNetCore.Http.HttpResults.Ok`1[SampleResponse],NotFound]'.`

How to check what results I am getting from my API and how to deserialize it?

I am expecting to be able to know which result type I am getting from API and deserialize my response to it.

0

There are 0 best solutions below