-Fixed populating ignored properties with DefaultValueHandling.IgnoreAndPopulate

This commit is contained in:
James Newton-King
2014-06-14 20:35:57 +12:00
parent 20eef9b608
commit af102d637f
2 changed files with 37 additions and 1 deletions
@@ -46,6 +46,42 @@ namespace Newtonsoft.Json.Tests.Serialization
[TestFixture]
public class DefaultValueHandlingTests : TestFixtureBase
{
public class MyClass
{
[JsonIgnore]
public MyEnum Status { get; set; }
private string _data;
public string Data
{
get { return _data; }
set
{
_data = value;
if (_data != null && _data.StartsWith("Other"))
{
this.Status = MyEnum.Other;
}
}
}
}
public enum MyEnum
{
Default = 0,
Other
}
[Test]
public void PopulateWithJsonIgnoreAttribute()
{
string json = "{\"Data\":\"Other with some more text\"}";
MyClass result = JsonConvert.DeserializeObject<MyClass>(json, new JsonSerializerSettings() { DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate });
Assert.AreEqual(MyEnum.Other, result.Status);
}
[Test]
public void Include()
{