-Performance
-Add CLSCompliant attributes -Fix BSON string reading bug
This commit is contained in:
@@ -1013,5 +1013,56 @@ namespace Newtonsoft.Json.Tests.Bson
|
||||
|
||||
Assert.IsFalse(reader.Read());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CanRoundTripStackOverflowData()
|
||||
{
|
||||
var doc =
|
||||
@"{
|
||||
""AboutMe"": ""<p>I'm the Director for Research and Development for <a href=\""http://www.prophoenix.com\"" rel=\""nofollow\"">ProPhoenix</a>, a public safety software company. This position allows me to investigate new and existing technologies and incorporate them into our product line, with the end goal being to help public safety agencies to do their jobs more effeciently and safely.</p>\r\n\r\n<p>I'm an advocate for PowerShell, as I believe it encourages administrative best practices and allows developers to provide additional access to their applications, without needing to explicity write code for each administrative feature. Part of my advocacy for PowerShell includes <a href=\""http://blog.usepowershell.com\"" rel=\""nofollow\"">my blog</a>, appearances on various podcasts, and acting as a Community Director for <a href=\""http://powershellcommunity.org\"" rel=\""nofollow\"">PowerShellCommunity.Org</a></p>\r\n\r\n<p>I’m also a co-host of Mind of Root (a weekly audio podcast about systems administration, tech news, and topics).</p>\r\n"",
|
||||
""WebsiteUrl"": ""http://blog.usepowershell.com""
|
||||
}";
|
||||
JObject parsed = JObject.Parse(doc);
|
||||
var memoryStream = new MemoryStream();
|
||||
var bsonWriter = new BsonWriter(memoryStream);
|
||||
parsed.WriteTo(bsonWriter);
|
||||
bsonWriter.Flush();
|
||||
memoryStream.Position = 0;
|
||||
|
||||
BsonReader reader = new BsonReader(memoryStream);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.StartObject, reader.TokenType);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
|
||||
Assert.AreEqual("AboutMe", reader.Value);
|
||||
Assert.AreEqual(typeof(string), reader.ValueType);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.String, reader.TokenType);
|
||||
Assert.AreEqual(@"<p>I'm the Director for Research and Development for <a href=""http://www.prophoenix.com"" rel=""nofollow"">ProPhoenix</a>, a public safety software company. This position allows me to investigate new and existing technologies and incorporate them into our product line, with the end goal being to help public safety agencies to do their jobs more effeciently and safely.</p>
|
||||
|
||||
<p>I'm an advocate for PowerShell, as I believe it encourages administrative best practices and allows developers to provide additional access to their applications, without needing to explicity write code for each administrative feature. Part of my advocacy for PowerShell includes <a href=""http://blog.usepowershell.com"" rel=""nofollow"">my blog</a>, appearances on various podcasts, and acting as a Community Director for <a href=""http://powershellcommunity.org"" rel=""nofollow"">PowerShellCommunity.Org</a></p>
|
||||
|
||||
<p>I’m also a co-host of Mind of Root (a weekly audio podcast about systems administration, tech news, and topics).</p>
|
||||
", reader.Value);
|
||||
Assert.AreEqual(typeof(string), reader.ValueType);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
|
||||
Assert.AreEqual("WebsiteUrl", reader.Value);
|
||||
Assert.AreEqual(typeof(string), reader.ValueType);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.String, reader.TokenType);
|
||||
Assert.AreEqual("http://blog.usepowershell.com", reader.Value);
|
||||
Assert.AreEqual(typeof(string), reader.ValueType);
|
||||
|
||||
Assert.IsTrue(reader.Read());
|
||||
Assert.AreEqual(JsonToken.EndObject, reader.TokenType);
|
||||
|
||||
Assert.IsFalse(reader.Read());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ using System.Text;
|
||||
using Newtonsoft.Json.Bson;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
namespace Newtonsoft.Json.Tests
|
||||
{
|
||||
@@ -442,17 +443,17 @@ namespace Newtonsoft.Json.Tests
|
||||
switch (method)
|
||||
{
|
||||
case SerializeMethod.JsonNet:
|
||||
return DeserializeJsonNet<T>((string) json);
|
||||
return DeserializeJsonNet<T>((string)json);
|
||||
case SerializeMethod.JsonNetBinary:
|
||||
return DeserializeJsonNetBinary<T>((byte[]) json);
|
||||
return DeserializeJsonNetBinary<T>((byte[])json);
|
||||
case SerializeMethod.BinaryFormatter:
|
||||
return DeserializeBinaryFormatter<T>((byte[]) json);
|
||||
return DeserializeBinaryFormatter<T>((byte[])json);
|
||||
case SerializeMethod.JavaScriptSerializer:
|
||||
return DeserializeWebExtensions<T>((string) json);
|
||||
return DeserializeWebExtensions<T>((string)json);
|
||||
case SerializeMethod.DataContractSerializer:
|
||||
return DeserializeDataContract<T>((string) json);
|
||||
return DeserializeDataContract<T>((string)json);
|
||||
case SerializeMethod.DataContractJsonSerializer:
|
||||
return DeserializeDataContractJson<T>((string) json);
|
||||
return DeserializeDataContractJson<T>((string)json);
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException("method");
|
||||
}
|
||||
@@ -462,8 +463,8 @@ namespace Newtonsoft.Json.Tests
|
||||
{
|
||||
MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(xml));
|
||||
|
||||
DataContractSerializer serializer = new DataContractSerializer(typeof (T));
|
||||
return (T) serializer.ReadObject(ms);
|
||||
DataContractSerializer serializer = new DataContractSerializer(typeof(T));
|
||||
return (T)serializer.ReadObject(ms);
|
||||
}
|
||||
|
||||
private T DeserializeBinaryFormatter<T>(byte[] bytes)
|
||||
@@ -487,7 +488,7 @@ namespace Newtonsoft.Json.Tests
|
||||
Integer = int.MaxValue,
|
||||
Text = "The quick red fox jumped over the lazy dog."
|
||||
};
|
||||
|
||||
|
||||
if (rootValue == null)
|
||||
rootValue = currentValue;
|
||||
if (parentValue != null)
|
||||
@@ -498,6 +499,47 @@ namespace Newtonsoft.Json.Tests
|
||||
|
||||
BenchmarkSerializeMethod(SerializeMethod.JsonNetBinary, rootValue);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void JObjectToString()
|
||||
{
|
||||
JObject test = JObject.Parse(JsonText);
|
||||
IsoDateTimeConverter isoDateTimeConverter = null;// = new IsoDateTimeConverter();
|
||||
|
||||
TimeOperation<object>(() =>
|
||||
{
|
||||
for (int i = 0; i < 5000; i++)
|
||||
{
|
||||
test["dummy"] = new JValue(i);
|
||||
Encoding.UTF8.GetBytes(test.ToString(Formatting.None));
|
||||
}
|
||||
return null;
|
||||
}, "JObject.ToString");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void JObjectToString2()
|
||||
{
|
||||
JObject test = JObject.Parse(JsonText);
|
||||
IsoDateTimeConverter isoDateTimeConverter = null;// = new IsoDateTimeConverter();
|
||||
MemoryStream ms = new MemoryStream();
|
||||
|
||||
TimeOperation<object>(() =>
|
||||
{
|
||||
for (int i = 0; i < 5000; i++)
|
||||
{
|
||||
test["dummy"] = new JValue(i);
|
||||
ms.Seek(0, SeekOrigin.Begin);
|
||||
JsonTextWriter jsonTextWriter = new JsonTextWriter(new StreamWriter(ms));
|
||||
test.WriteTo(jsonTextWriter);
|
||||
jsonTextWriter.Flush();
|
||||
ms.ToArray();
|
||||
|
||||
//Encoding.UTF8.GetBytes(test.ToString(Formatting.None));
|
||||
}
|
||||
return null;
|
||||
}, "JObject.ToString");
|
||||
}
|
||||
}
|
||||
|
||||
public class LargeRecursiveTestClass
|
||||
|
||||
Reference in New Issue
Block a user