-
Notifications
You must be signed in to change notification settings - Fork 0
Serializer
Anrijs Vitolins edited this page Feb 19, 2022
·
2 revisions
Package by default uses Json.Net serializer internally without any need of setting it up.
In case you want to swap it to System.Text.Json
serializer (also included in package) or wire up your own, you just have to use extended constructor for your rest client.
It is included in package and you just have to register it with dependency injection:
services.AddScoped<IObjectSerializer, SystemTextJsonObjectSerializer>();
and then use extended constructor on your rest client class:
ublic class TypedClient : AbstractRestClient
{
public TypedClient(
HttpClient httpClient,
ClientSettings settings,
ILogger<TypedClient> logger,
IObjectSerializer serializer)
: base(httpClient, settings, logger, serializer)
{ }
}
That's it. Now it uses System.Text.Json
for serialization needs.
For that you have to create class and implement IObjectSerializer
interface, which has only two methods - serialize and deserialize.
After that its the same as with System.Text.Json above, just register it and add to rest client constructor.
services.AddScoped<IObjectSerializer, MyCoolSerializer>();