Skip to content

Latest commit

 

History

History
50 lines (44 loc) · 1.68 KB

NamingStrategySkipSpecifiedNames.md

File metadata and controls

50 lines (44 loc) · 1.68 KB

Configure NamingStrategy property name serialization

This sample configures a Argon.CamelCaseNamingStrategy to not camel case properties that already have a name specified with an attribute.

public class User
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    [JsonProperty(PropertyName = "UPN")] public string Upn { get; set; }
}

snippet source | anchor

var user = new User
{
    FirstName = "John",
    LastName = "Smith",
    Upn = "[email protected]"
};

var contractResolver = new DefaultContractResolver
{
    NamingStrategy = new CamelCaseNamingStrategy
    {
        OverrideSpecifiedNames = false
    }
};

var json = JsonConvert.SerializeObject(user, new JsonSerializerSettings
{
    ContractResolver = contractResolver,
    Formatting = Formatting.Indented
});

Console.WriteLine(json);
// {
//   "firstName": "John",
//   "lastName": "Smith",
//   "UPN": "[email protected]"
// }

snippet source | anchor