This sample deserializes JSON with Argon.ObjectCreationHandling
set to Replace so that collection values aren't duplicated.
public class UserViewModel
{
public string Name { get; set; }
public IList<string> Offices { get; } = new List<string>
{
"Auckland",
"Wellington",
"Christchurch"
};
}
var json = """
{
'Name': 'James',
'Offices': [
'Auckland',
'Wellington',
'Christchurch'
]
}
""";
var model1 = JsonConvert.DeserializeObject<UserViewModel>(json);
foreach (var office in model1.Offices)
{
Console.WriteLine(office);
}
// Auckland
// Wellington
// Christchurch
// Auckland
// Wellington
// Christchurch
var model2 = JsonConvert.DeserializeObject<UserViewModel>(json, new JsonSerializerSettings
{
ObjectCreationHandling = ObjectCreationHandling.Replace
});
foreach (var office in model2.Offices)
{
Console.WriteLine(office);
}
// Auckland
// Wellington
// Christchurch