-Added reading and writing binary JSON (BSON) support - work in progress
-Added BsonReader, BsonWriter -Added support for reading and writing byte arrays to JsonReader, JsonWriter and LINQ to JSON classes -Added ReadAsBytes to JsonReader -Changed Silverlight build serializer to look for a TypeConverter -Changed .NET build to not rely on System.ComponentModel.DataAnnotations assembly to support .NET 4.0 client profile -Remove DateTimeOffset stand-in from Compact Framework build -Fixed .NET 2.0 build to run on environments without .NET 2.0 SP1 -Fixed deserialization to always use a new value created from a JsonConverter -Fixed XmlNodeConverter to support converting comments in JSON
This commit is contained in:
@@ -142,6 +142,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !PocketPC && !NET20
|
||||
[Test]
|
||||
public void SerializeDateTimeOffset()
|
||||
{
|
||||
@@ -266,6 +267,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
string json2 = JsonConvert.SerializeObject(c, new IsoDateTimeConverter() { DateTimeStyles = DateTimeStyles.AssumeUniversal });
|
||||
Assert.AreNotEqual(json, json2);
|
||||
}
|
||||
#endif
|
||||
|
||||
[Test]
|
||||
public void BlogCodeSample()
|
||||
|
||||
@@ -47,6 +47,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
Assert.AreEqual("new Date(976918263055)", result);
|
||||
}
|
||||
|
||||
#if !PocketPC && !NET20
|
||||
[Test]
|
||||
public void SerializeDateTimeOffset()
|
||||
{
|
||||
@@ -85,15 +86,6 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
Assert.AreEqual(@"{""PreField"":null,""DateTimeField"":new Date(976918263055),""DateTimeOffsetField"":new Date(976918263055),""PostField"":null}", result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeserializeDateTime()
|
||||
{
|
||||
JavaScriptDateTimeConverter converter = new JavaScriptDateTimeConverter();
|
||||
|
||||
DateTime result = JsonConvert.DeserializeObject<DateTime>("new Date(976918263055)", converter);
|
||||
Assert.AreEqual(new DateTime(2000, 12, 15, 22, 11, 3, 55, DateTimeKind.Utc), result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(Exception), ExpectedMessage = "Cannot convert null value to System.DateTime.")]
|
||||
public void DeserializeNullToNonNullable()
|
||||
@@ -113,5 +105,15 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
DateTimeOffset result = JsonConvert.DeserializeObject<DateTimeOffset>(json, converter);
|
||||
Assert.AreEqual(new DateTimeOffset(2000, 12, 15, 22, 11, 3, 55, TimeSpan.Zero), result);
|
||||
}
|
||||
#endif
|
||||
|
||||
[Test]
|
||||
public void DeserializeDateTime()
|
||||
{
|
||||
JavaScriptDateTimeConverter converter = new JavaScriptDateTimeConverter();
|
||||
|
||||
DateTime result = JsonConvert.DeserializeObject<DateTime>("new Date(976918263055)", converter);
|
||||
Assert.AreEqual(new DateTime(2000, 12, 15, 22, 11, 3, 55, DateTimeKind.Utc), result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -523,6 +523,35 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
string json = JsonConvert.SerializeXmlNode(doc);
|
||||
Assert.AreEqual(@"{""name"":""O\""Connor""}", json);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SerializeComment()
|
||||
{
|
||||
string xml = @"<span class=""vevent"">
|
||||
<a class=""url"" href=""http://www.web2con.com/"">Text</a><!-- Hi! -->
|
||||
</span>";
|
||||
XmlDocument doc = new XmlDocument();
|
||||
doc.LoadXml(xml);
|
||||
|
||||
string jsonText = JsonConvert.SerializeObject(doc, Formatting.Indented, new XmlNodeConverter());
|
||||
|
||||
string expected = @"{
|
||||
""span"": {
|
||||
""@class"": ""vevent"",
|
||||
""a"": {
|
||||
""@class"": ""url"",
|
||||
""@href"": ""http://www.web2con.com/"",
|
||||
""#text"": ""Text""
|
||||
}/* Hi! */
|
||||
}
|
||||
}";
|
||||
|
||||
Assert.AreEqual(expected, jsonText);
|
||||
|
||||
XmlDocument newDoc = JsonConvert.DeserializeObject<XmlDocument>(jsonText, new XmlNodeConverter());
|
||||
Assert.AreEqual(@"<span class=""vevent""><a class=""url"" href=""http://www.web2con.com/"">Text</a><!-- Hi! --></span>", newDoc.InnerXml);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user