Skip to content

Latest commit

 

History

History
34 lines (30 loc) · 1.05 KB

DefaultSettings.md

File metadata and controls

34 lines (30 loc) · 1.05 KB

Serialize with DefaultSettings

This sample serializes and deserializes JSON using Argon.JsonConvert.DefaultSettings.

// settings will automatically be used by JsonConvert.SerializeObject/DeserializeObject
JsonConvert.DefaultSettings = () => new()
{
    Formatting = Formatting.Indented,
    ContractResolver = new CamelCasePropertyNamesContractResolver()
};

var s = new Staff
{
    FirstName = "Eric",
    LastName = "Example",
    BirthDate = new(1980, 4, 20, 0, 0, 0, DateTimeKind.Utc),
    Department = "IT",
    JobTitle = "Web Dude"
};

json = JsonConvert.SerializeObject(s);
// {
//   "firstName": "Eric",
//   "lastName": "Example",
//   "birthDate": "1980-04-20T00:00:00Z",
//   "department": "IT",
//   "jobTitle": "Web Dude"
// }

snippet source | anchor