Click or drag to resize
Json.NETJsonConverterAttribute on a property
 

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

Sample
Types
 1public enum UserStatus
 2{
 3    NotConfirmed,
 4    Active,
 5    Deleted
 6}
 7
 8public class User
 9{
10    public string UserName { get; set; }
11
12    [JsonConverter(typeof(StringEnumConverter))]
13    public UserStatus Status { get; set; }
14}
Usage
 1User user = new User
 2{
 3    UserName = @"domain\username",
 4    Status = UserStatus.Deleted
 5};
 6
 7string json = JsonConvert.SerializeObject(user, Formatting.Indented);
 8
 9Console.WriteLine(json);
10// {
11//   "UserName": "domain\\username",
12//   "Status": "Deleted"
13// }