-Added even more detail to no root XML element exception message when converting JSON to XML. Seriously, if you still get stuck here you're an idiot
-Added NullValueHandling, DefaultValueHandling and ReferenceLoopHandling to JsonPropertyAttribute -Change JsonMemberMapping from a struct to a class. Now has too many properties for a struct
This commit is contained in:
@@ -32,6 +32,7 @@ using NUnit.Framework;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Newtonsoft.Json.Utilities;
|
||||
using System.Globalization;
|
||||
using System.Xml;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Converters
|
||||
{
|
||||
@@ -255,5 +256,26 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
string json2 = JsonConvert.SerializeObject(c, new IsoDateTimeConverter() { DateTimeStyles = DateTimeStyles.AssumeUniversal });
|
||||
Assert.AreNotEqual(json, json2);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BlogCodeSample()
|
||||
{
|
||||
Person p = new Person
|
||||
{
|
||||
Name = "Keith",
|
||||
BirthDate = new DateTime(1980, 3, 8),
|
||||
LastModified = new DateTime(2009, 4, 12, 20, 44, 55),
|
||||
};
|
||||
|
||||
string jsonText = JsonConvert.SerializeObject(p, new IsoDateTimeConverter());
|
||||
// {
|
||||
// "Name": "Keith",
|
||||
// "BirthDate": "1980-03-08T00:00:00",
|
||||
// "LastModified": "2009-04-12T20:44:55"
|
||||
// }
|
||||
|
||||
Console.WriteLine(jsonText);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,7 @@ using System.IO;
|
||||
using System.Xml;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Newtonsoft.Json.Utilities;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Converters
|
||||
{
|
||||
@@ -348,7 +349,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(JsonSerializationException), ExpectedMessage = "JSON root object has multiple properties. The root object must have a single property in order to create a valid XML document.")]
|
||||
[ExpectedException(typeof(JsonSerializationException), ExpectedMessage = "JSON root object has multiple properties. The root object must have a single property in order to create a valid XML document. Consider specifing a DeserializeRootElementName.")]
|
||||
public void RootObjectMultipleProperties()
|
||||
{
|
||||
XmlDocument newDoc = (XmlDocument)JsonConvert.DeserializeXmlNode(@"{Prop1:1,Prop2:2}");
|
||||
@@ -417,7 +418,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(JsonSerializationException), ExpectedMessage = "JSON root object has multiple properties. The root object must have a single property in order to create a valid XML document.")]
|
||||
[ExpectedException(typeof(JsonSerializationException), ExpectedMessage = "JSON root object has multiple properties. The root object must have a single property in order to create a valid XML document. Consider specifing a DeserializeRootElementName.")]
|
||||
public void MultipleRootProperties()
|
||||
{
|
||||
string strJSON = @"{
|
||||
|
||||
Reference in New Issue
Block a user