-Added Populate and IgnoreAndPopulate options to DefaultValueHandling for automatically populating default values during deserialization

This commit is contained in:
JamesNK
2011-08-01 02:05:14 +00:00
parent ce2b5e02e0
commit bc726f1b6d
9 changed files with 123 additions and 24 deletions
@@ -50,7 +50,7 @@ namespace Newtonsoft.Json.Tests.Serialization
}
[Test]
public void DefaultValueAttributeTest()
public void SerializeDefaultValueAttributeTest()
{
string json = JsonConvert.SerializeObject(new DefaultValueAttributeTestClass(),
Formatting.None, new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Ignore });
@@ -69,6 +69,24 @@ namespace Newtonsoft.Json.Tests.Serialization
Assert.AreEqual(@"{}", json);
}
[Test]
public void DeserializeDefaultValueAttributeTest()
{
string json = "{}";
DefaultValueAttributeTestClass c = JsonConvert.DeserializeObject<DefaultValueAttributeTestClass>(json, new JsonSerializerSettings
{
DefaultValueHandling = DefaultValueHandling.Populate
});
Assert.AreEqual("TestProperty1Value", c.TestProperty1);
c = JsonConvert.DeserializeObject<DefaultValueAttributeTestClass>(json, new JsonSerializerSettings
{
DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate
});
Assert.AreEqual("TestProperty1Value", c.TestProperty1);
}
[JsonObject]
public class NetworkUser
{