Skip to content

Latest commit

 

History

History
59 lines (53 loc) · 1.82 KB

NamingStrategySkipDictionaryKeys.md

File metadata and controls

59 lines (53 loc) · 1.82 KB

Configure CamelCaseNamingStrategy

This sample configures a Argon.CamelCaseNamingStrategy to not camel case dictionary keys.

public class DailyHighScores
{
    public DateTime Date { get; set; }
    public string Game { get; set; }
    public Dictionary<string, int> UserPoints { get; set; }
}

snippet source | anchor

var dailyHighScores = new DailyHighScores
{
    Date = new(2016, 6, 27, 0, 0, 0, DateTimeKind.Utc),
    Game = "Donkey Kong",
    UserPoints = new()
    {
        ["JamesNK"] = 9001,
        ["JoC"] = 1337,
        ["JessicaN"] = 1000
    }
};

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

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

Console.WriteLine(json);
// {
//   "date": "2016-06-27T00:00:00Z",
//   "game": "Donkey Kong",
//   "userPoints": {
//     "JamesNK": 9001,
//     "JoC": 1337,
//     "JessicaN": 1000
//   }
// }

snippet source | anchor