-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
@@ -1300,16 +1300,19 @@ keyword such as type of business.""
}
[Test]
public void JsonPropertyWithHandlingValues()
public void SerializeJsonPropertyWithHandlingValues()
{
JsonPropertyWithHandlingValues o = new JsonPropertyWithHandlingValues();
o.DefaultValueHandlingIgnoreProperty = "Default!";
o.DefaultValueHandlingIncludeProperty = "Default!";
o.DefaultValueHandlingPopulateProperty = "Default!";
o.DefaultValueHandlingIgnoreAndPopulateProperty = "Default!";
string json = JsonConvert.SerializeObject(o, Formatting.Indented);
Assert.AreEqual(@"{
""DefaultValueHandlingIncludeProperty"": ""Default!"",
""DefaultValueHandlingPopulateProperty"": ""Default!"",
""NullValueHandlingIncludeProperty"": null,
""ReferenceLoopHandlingErrorProperty"": null,
""ReferenceLoopHandlingIgnoreProperty"": null,
@@ -1320,10 +1323,23 @@ keyword such as type of business.""
Assert.AreEqual(@"{
""DefaultValueHandlingIncludeProperty"": ""Default!"",
""DefaultValueHandlingPopulateProperty"": ""Default!"",
""NullValueHandlingIncludeProperty"": null
}", json);
}
[Test]
public void DeserializeJsonPropertyWithHandlingValues()
{
string json = "{}";
JsonPropertyWithHandlingValues o = JsonConvert.DeserializeObject<JsonPropertyWithHandlingValues>(json);
Assert.AreEqual("Default!", o.DefaultValueHandlingIgnoreAndPopulateProperty);
Assert.AreEqual("Default!", o.DefaultValueHandlingPopulateProperty);
Assert.AreEqual(null, o.DefaultValueHandlingIgnoreProperty);
Assert.AreEqual(null, o.DefaultValueHandlingIncludeProperty);
}
[Test]
[ExpectedException(typeof(JsonSerializationException))]
public void JsonPropertyWithHandlingValues_ReferenceLoopError()