Skip to content

Serialization

Stanislav Molchanovskiy edited this page Nov 15, 2021 · 1 revision

Serialization is needed to convert data when sending requests and receiving responses. By default, System.Text.Json is used for serialization. But you can replace it with other options:

IMyClient myClient = NClientGallery.Clients.GetCustom()
    .For<IMyClient>(host: "http://localhost:8080")
    .WithSystemJsonSerialization()     // It is already in use, so it is not necessary to call this method
    // or
    .WithJsonSerialization()           // This is the alias for WithJsonSerialization
    // or
    .WithNewtonsoftJsonSerialization()
    // or
    .WithSystemXmlSerialization()
    ...
    .Build();

You can also create your own implementation of the ISerializerProvider and pass it to the WithCustomSerializer method:

ISerializerProvider serializerProvider = ...;

IMyClient myClient = NClientGallery.Clients.GetRest()
    .For<IMyClient>(host: "http://localhost:8080")
    .WithCustomSerialization(serializerProvider)
    .Build();