-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:
@@ -103,13 +103,21 @@ namespace Newtonsoft.Json.Tests
|
||||
jsonWriter.WriteValue((decimal?)1.1m);
|
||||
jsonWriter.WriteValue((DateTime?)null);
|
||||
jsonWriter.WriteValue((DateTime?)new DateTime(JsonConvert.InitialJavaScriptDateTicks, DateTimeKind.Utc));
|
||||
#if !PocketPC && !NET20
|
||||
jsonWriter.WriteValue((DateTimeOffset?)null);
|
||||
jsonWriter.WriteValue((DateTimeOffset?)new DateTimeOffset(JsonConvert.InitialJavaScriptDateTicks, TimeSpan.Zero));
|
||||
#endif
|
||||
jsonWriter.WriteEndArray();
|
||||
}
|
||||
|
||||
string json = sw.ToString();
|
||||
string expected = @"[null,""c"",null,true,null,1,null,1,null,1,null,1,null,1,null,1,null,1,null,1,null,1.1,null,1.1,null,1.1,null,""\/Date(0)\/"",null,""\/Date(0+0000)\/""]";
|
||||
string expected;
|
||||
|
||||
#if !PocketPC && !NET20
|
||||
expected = @"[null,""c"",null,true,null,1,null,1,null,1,null,1,null,1,null,1,null,1,null,1,null,1.1,null,1.1,null,1.1,null,""\/Date(0)\/"",null,""\/Date(0+0000)\/""]";
|
||||
#else
|
||||
expected = @"[null,""c"",null,true,null,1,null,1,null,1,null,1,null,1,null,1,null,1,null,1,null,1.1,null,1.1,null,1.1,null,""\/Date(0)\/""]";
|
||||
#endif
|
||||
|
||||
Assert.AreEqual(expected, json);
|
||||
}
|
||||
@@ -532,5 +540,65 @@ _____'propertyName': NaN
|
||||
|
||||
Assert.AreEqual(expected, result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WriteSingleBytes()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
StringWriter sw = new StringWriter(sb);
|
||||
|
||||
string text = "Hello world.";
|
||||
byte[] data = Encoding.UTF8.GetBytes(text);
|
||||
|
||||
using (JsonTextWriter jsonWriter = new JsonTextWriter(sw))
|
||||
{
|
||||
jsonWriter.Formatting = Formatting.Indented;
|
||||
Assert.AreEqual(Formatting.Indented, jsonWriter.Formatting);
|
||||
|
||||
jsonWriter.WriteValue(data);
|
||||
}
|
||||
|
||||
string expected = @"""SGVsbG8gd29ybGQu""";
|
||||
string result = sb.ToString();
|
||||
|
||||
Assert.AreEqual(expected, result);
|
||||
|
||||
byte[] d2 = Convert.FromBase64String(result.Trim('"'));
|
||||
|
||||
Assert.AreEqual(text, Encoding.UTF8.GetString(d2, 0, d2.Length));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WriteBytesInArray()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
StringWriter sw = new StringWriter(sb);
|
||||
|
||||
string text = "Hello world.";
|
||||
byte[] data = Encoding.UTF8.GetBytes(text);
|
||||
|
||||
using (JsonTextWriter jsonWriter = new JsonTextWriter(sw))
|
||||
{
|
||||
jsonWriter.Formatting = Formatting.Indented;
|
||||
Assert.AreEqual(Formatting.Indented, jsonWriter.Formatting);
|
||||
|
||||
jsonWriter.WriteStartArray();
|
||||
jsonWriter.WriteValue(data);
|
||||
jsonWriter.WriteValue(data);
|
||||
jsonWriter.WriteValue((object)data);
|
||||
jsonWriter.WriteValue((byte[])null);
|
||||
jsonWriter.WriteEndArray();
|
||||
}
|
||||
|
||||
string expected = @"[
|
||||
""SGVsbG8gd29ybGQu"",
|
||||
""SGVsbG8gd29ybGQu"",
|
||||
""SGVsbG8gd29ybGQu"",
|
||||
null
|
||||
]";
|
||||
string result = sb.ToString();
|
||||
|
||||
Assert.AreEqual(expected, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user