Skip to content

Latest commit

 

History

History
44 lines (37 loc) · 1.43 KB

JsonConverterAttributeProperty.md

File metadata and controls

44 lines (37 loc) · 1.43 KB

JsonConverterAttribute on a property

This sample uses the Argon.JsonConverterAttribute to specify that a Argon.JsonConverter should be used when serializing and deserializing a property.

public enum UserStatus
{
    NotConfirmed,
    Active,
    Deleted
}

public class User
{
    public string UserName { get; set; }

    [JsonConverter(typeof(StringEnumConverter))]
    public UserStatus Status { get; set; }
}

snippet source | anchor

var user = new User
{
    UserName = @"domain\username",
    Status = UserStatus.Deleted
};

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

Console.WriteLine(json);
// {
//   "UserName": "domain\\username",
//   "Status": "Deleted"
// }

snippet source | anchor