-Improved default null and value handing when JSON value is not compatible with property value
-Added interfaces, structs and enums as valid targets of JsonConverterAttribute
This commit is contained in:
@@ -35,6 +35,20 @@ namespace Newtonsoft.Json.Tests.Serialization
|
||||
{
|
||||
public class NullValueHandlingTests : TestFixtureBase
|
||||
{
|
||||
[Test]
|
||||
public void DeserializeNullIntoDateTime()
|
||||
{
|
||||
DateTimeTestClass c = JsonConvert.DeserializeObject<DateTimeTestClass>(@"{DateTimeField:null}", new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
|
||||
Assert.AreEqual(c.DateTimeField, default(DateTime));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeserializeEmptyStringIntoDateTimeWithEmptyStringDefaultValue()
|
||||
{
|
||||
DateTimeTestClass c = JsonConvert.DeserializeObject<DateTimeTestClass>(@"{DateTimeField:""""}", new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
|
||||
Assert.AreEqual(c.DateTimeField, default(DateTime));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NullValueHandlingSerialization()
|
||||
{
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#if !PocketPC && !NET20
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
@@ -34,6 +35,8 @@ namespace Newtonsoft.Json.Tests.TestObjects
|
||||
public class DateTimeTestClass
|
||||
{
|
||||
public string PreField { get; set; }
|
||||
[DefaultValue("")]
|
||||
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||
public DateTime DateTimeField { get; set; }
|
||||
public DateTimeOffset DateTimeOffsetField { get; set; }
|
||||
public string PostField { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user