-Added constructor to StringEnumConverter for setting camelcase from attribute
This commit is contained in:
@@ -104,6 +104,28 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
public NegativeEnum Value2 { get; set; }
|
||||
}
|
||||
|
||||
[JsonConverter(typeof(StringEnumConverter), true)]
|
||||
public enum CamelCaseEnum
|
||||
{
|
||||
This,
|
||||
Is,
|
||||
CamelCase
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Serialize_CamelCaseFromAttribute()
|
||||
{
|
||||
string json = JsonConvert.SerializeObject(CamelCaseEnum.CamelCase);
|
||||
Assert.AreEqual(@"""camelCase""", json);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Deserialize_CamelCaseFromAttribute()
|
||||
{
|
||||
CamelCaseEnum e = JsonConvert.DeserializeObject<CamelCaseEnum>(@"""camelCase""");
|
||||
Assert.AreEqual(CamelCaseEnum.CamelCase, e);
|
||||
}
|
||||
|
||||
#if !NET20
|
||||
[Test]
|
||||
public void NamedEnumDuplicateTest()
|
||||
|
||||
@@ -63,6 +63,16 @@ namespace Newtonsoft.Json.Converters
|
||||
AllowIntegerValues = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="StringEnumConverter"/> class.
|
||||
/// </summary>
|
||||
/// <param name="camelCaseText"><c>true</c> if the written enum text will be camel case; otherwise, <c>false</c>.</param>
|
||||
public StringEnumConverter(bool camelCaseText)
|
||||
: this()
|
||||
{
|
||||
CamelCaseText = camelCaseText;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the JSON representation of the object.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user