-Built-in converters inherit from JsonConverter

-Fixed writing null values by XmlNodeConverter and RegexConverter
-Tests
-Documentation
This commit is contained in:
James Newton-King
2017-08-12 20:17:28 +12:00
parent 0996a59f8c
commit 946b43fab8
15 changed files with 268 additions and 36 deletions
@@ -36,6 +36,7 @@ using NUnit.Framework;
using Newtonsoft.Json.Serialization;
using Newtonsoft.Json.Tests.TestObjects;
using System.Data;
using System.IO;
namespace Newtonsoft.Json.Tests.Converters
{
@@ -107,6 +108,18 @@ namespace Newtonsoft.Json.Tests.Converters
public DataSet Set { get; set; }
}
[Test]
public void WriteJsonNull()
{
StringWriter sw = new StringWriter();
JsonTextWriter jsonWriter = new JsonTextWriter(sw);
DataSetConverter converter = new DataSetConverter();
converter.WriteJson(jsonWriter, null, null);
StringAssert.AreEqual(@"null", sw.ToString());
}
[Test]
public void SerializeNull()
{
@@ -45,6 +45,18 @@ namespace Newtonsoft.Json.Tests.Converters
{
public class DataTableConverterTests : TestFixtureBase
{
[Test]
public void WriteJsonNull()
{
StringWriter sw = new StringWriter();
JsonTextWriter jsonWriter = new JsonTextWriter(sw);
DataTableConverter converter = new DataTableConverter();
converter.WriteJson(jsonWriter, null, null);
StringAssert.AreEqual(@"null", sw.ToString());
}
[Test]
public void Deserialize()
{
@@ -50,6 +50,18 @@ namespace Newtonsoft.Json.Tests.Converters
public Regex Regex { get; set; }
}
[Test]
public void WriteJsonNull()
{
StringWriter sw = new StringWriter();
JsonTextWriter jsonWriter = new JsonTextWriter(sw);
RegexConverter converter = new RegexConverter();
converter.WriteJson(jsonWriter, null, null);
StringAssert.AreEqual(@"null", sw.ToString());
}
[Test]
public void SerializeToText()
{
@@ -24,6 +24,7 @@
#endregion
using System;
using System.IO;
using Newtonsoft.Json.Converters;
#if DNXCORE50
using Xunit;
@@ -92,6 +93,18 @@ namespace Newtonsoft.Json.Tests.Converters
}
}
[Test]
public void WriteJsonNull()
{
StringWriter sw = new StringWriter();
JsonTextWriter jsonWriter = new JsonTextWriter(sw);
VersionConverter converter = new VersionConverter();
converter.WriteJson(jsonWriter, null, null);
StringAssert.AreEqual(@"null", sw.ToString());
}
[Test]
public void SerializeVersionClass()
{
@@ -151,6 +151,18 @@ namespace Newtonsoft.Json.Tests.Converters
return sw.ToString();
}
[Test]
public void WriteJsonNull()
{
StringWriter sw = new StringWriter();
JsonTextWriter jsonWriter = new JsonTextWriter(sw);
XmlNodeConverter converter = new XmlNodeConverter();
converter.WriteJson(jsonWriter, null, null);
StringAssert.AreEqual(@"null", sw.ToString());
}
#if !NET20
[Test]
public void SerializeDollarProperty()