This sample uses Argon.JsonPropertyAttribute
to set Argon.Required
which is used during deserialization to validate the presence of required JSON properties.
public class Videogame
{
[JsonProperty(Required = Required.Always)]
public string Name { get; set; }
[JsonProperty(Required = Required.AllowNull)]
public DateTime? ReleaseDate { get; set; }
}
var json = """
{
'Name': 'Starcraft III',
'ReleaseDate': null
}
""";
var starcraft = JsonConvert.DeserializeObject<Videogame>(json);
Console.WriteLine(starcraft.Name);
// Starcraft III
Console.WriteLine(starcraft.ReleaseDate);
// null