Serialization

Under the hood RestClient uses Json.NET for serialization, this means you can use all the power of Json.NET to ensure your models are (de)serialized properly.

JsonSerializerSettings

Since version 3.3.1 you can use SetJsonSerializerSettings to provide JsonSerializerSettings for DalSoft.RestClient to use.

// When directly creating a RestClient instance
dynamic restClient = new RestClient("https://dalsoft.co.uk", new Config()
	.SetJsonSerializerSettings(new JsonSerializerSettings { ContractResolver =  new DefaultContractResolver { NamingStrategy = new SnakeCaseNamingStrategy() } }));

// When using IHttpClientFactory
 services
	.AddRestClient(Name, "https://dalsoft.co.uk")
	.SetJsonSerializerSettings(new JsonSerializerSettings { ContractResolver =  new DefaultContractResolver { NamingStrategy = new SnakeCaseNamingStrategy() } });

Serialization Attributes

On a per class basis you can Json.NET Serialization attributes to control DalSoft.RestClient serialization.

public class User
{
  [JsonProperty("phone_number")]
  public string PhoneNumber { get; set; }
}

dynamic restClient = new RestClient("http://jsonplaceholder.typicode.com");

/* http://jsonplaceholder.typicode.com/users/1  response / request body {phone_number:"+44 12345"}; */
User response = await restClient.Users(1).Put(new User { PhoneNumber = "+44 12345" });

//PhoneNumber has JsonProperty attribute
Assert.That(response.PhoneNumber, Is.EqualTo("+44 12345"));

You can use Json.NET JsonSerializerSettings or Serialization Attributes to control pretty much anything to do with serialization.