In the current code which is using older version of RestSharp there is option to specify the default JsonSerializer, I am not able to figure out how to do specify request.JsonSerializer in version 107
var request = new RestRequest("abc");
request.AddHeader(Constants.HttpHeaderNames.ContentType, "application/json; charset=utf-8");
request.JsonSerializer = NewtonsoftJsonSerializer.Default;
Request-specific serializers are no longer supported. The proper way of using RestSharp (similar to HttpClient) is to have one instance per API client instance. Normally, an API you talk to has the same serialization for all its endpoints.
If you must use NewtonsoftJson, use it as described in the docs.
client.UseNewtonsoftJson();
And please, don't add the content type header.
As the API might change, you can always reference to the latest version docs.
UPDATE 26 April 2023
The current latest v110 has the serialiser configuration moved to RestSharpOptions. It was done to avoid changing the serialiser during concurrent calls, which might create weird side effects.
The new API can be used like this:
var client = new RestClient(
options,
configureSerialization: s => s.UseSerializer(() => new CustomSerializer());
);
There is a discussion to add an option to have a serialiser set per request.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With