Add construct public StringEnumConverter(bool camelCaseText, bool all… (#1700)
This commit is contained in:
@@ -139,6 +139,20 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
CamelCase
|
||||
}
|
||||
|
||||
[JsonConverter(typeof(StringEnumConverter), true, false)]
|
||||
public enum NotAllowIntegerValuesEnum
|
||||
{
|
||||
Foo = 0,
|
||||
Bar = 1
|
||||
}
|
||||
|
||||
[JsonConverter(typeof(StringEnumConverter), true, true)]
|
||||
public enum AllowIntegerValuesEnum
|
||||
{
|
||||
Foo = 0,
|
||||
Bar = 1
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Serialize_CamelCaseFromAttribute()
|
||||
{
|
||||
@@ -153,6 +167,22 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
Assert.AreEqual(CamelCaseEnum.CamelCase, e);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Deserialize_NotAllowIntegerValuesFromAttribute()
|
||||
{
|
||||
ExceptionAssert.Throws<JsonSerializationException>(() =>
|
||||
{
|
||||
NotAllowIntegerValuesEnum e = JsonConvert.DeserializeObject<NotAllowIntegerValuesEnum>(@"""9""");
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Deserialize_AllowIntegerValuesAttribute()
|
||||
{
|
||||
AllowIntegerValuesEnum e = JsonConvert.DeserializeObject<AllowIntegerValuesEnum>(@"""9""");
|
||||
Assert.AreEqual(9, (int)e);
|
||||
}
|
||||
|
||||
#if !NET20
|
||||
[Test]
|
||||
public void NamedEnumDuplicateTest()
|
||||
|
||||
Reference in New Issue
Block a user