Skip to content

Latest commit

 

History

History
38 lines (32 loc) · 1.35 KB

JsonPropertyPropertyLevelSetting.md

File metadata and controls

38 lines (32 loc) · 1.35 KB

JsonPropertyAttribute property setting

This sample uses Argon.JsonPropertyAttribute to change how the property value is serialized.

public class Vessel
{
    public string Name { get; set; }
    public string Class { get; set; }

    [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
    public DateTime? LaunchDate { get; set; }
}

snippet source | anchor

var vessel = new Vessel
{
    Name = "Red October",
    Class = "Typhoon"
};

var json = JsonConvert.SerializeObject(vessel, Formatting.Indented);

Console.WriteLine(json);
// {
//   "Name": "Red October",
//   "Class": "Typhoon"
// }

snippet source | anchor