Configure RestSharp client with correct serialization

RestSharp

The default deserializer does not work for some cases, so it is better to use the one that ships with .NET core


string baseUri = _configuration["ApiUrl"];

RestClientOptions restClientOptions = new()
{
   BaseUrl = new Uri(baseUri),
   RemoteCertificateValidationCallback = (_, _, _, _) => true,
   ThrowOnDeserializationError = true
};

_restClient = new(restClientOptions);
_restClient.UseSystemTextJson(new JsonSerializerOptions()
{
   PropertyNameCaseInsensitive = true,
});

Post a Comment

Previous Post Next Post