-Fix JsonSerializer.Deserialize to take a TextReader instead of a StringReader

This commit is contained in:
JamesNK
2008-09-08 09:03:21 +00:00
parent d193ae37be
commit ce0148d67f
2 changed files with 55 additions and 5 deletions
+53 -3
View File
@@ -36,7 +36,7 @@ namespace Newtonsoft.Json.Tests
StringWriter sw = new StringWriter();
Newtonsoft.Json.JsonTextWriter writer = new JsonTextWriter(sw);
if (false)
if (true)
writer.Formatting = Formatting.Indented;
else
writer.Formatting = Formatting.None;
@@ -61,9 +61,8 @@ namespace Newtonsoft.Json.Tests
[Test]
public void PerformanceTest2()
public void Serialize()
{
TestClass test = new TestClass();
test.Address1.Address = "fff Street";
@@ -98,6 +97,57 @@ namespace Newtonsoft.Json.Tests
Console.WriteLine("{0}", timed.ElapsedMilliseconds + " ms");
Console.WriteLine("{0}", json);
}
[Test]
public void Deserialize()
{
string json = @"{
""strings"": [
""Rick"",
""Markus egger ][, (2nd)"",
""Kevin McNeish""
],
""dictionary"": {
""Val asd1"": 1,
""Val2"": 3,
""Val3"": 4
},
""Name"": ""Rick"",
""Now"": ""\/Date(1220867547892+1200)\/"",
""BigNumber"": 34123123123.121,
""Address1"": {
""Address"": ""fff Street"",
""Phone"": ""(503) 814-6335"",
""Entered"": ""\/Date(1222588347892+1300)\/""
},
""Addresses"": [
{
""Address"": ""array address"",
""Phone"": ""(503) 814-6335"",
""Entered"": ""\/Date(1220777547892+1200)\/""
},
{
""Address"": ""array 2 address"",
""Phone"": ""(503) 814-6335"",
""Entered"": ""\/Date(1220691147893+1200)\/""
}
]
}";
for (int x = 0; x < 10000; x++)
{
Newtonsoft.Json.JsonSerializer serializer = new Newtonsoft.Json.JsonSerializer();
serializer.NullValueHandling = NullValueHandling.Ignore;
serializer.ObjectCreationHandling = Newtonsoft.Json.ObjectCreationHandling.Replace;
serializer.MissingMemberHandling = Newtonsoft.Json.MissingMemberHandling.Ignore;
serializer.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
TestClass test = (TestClass)serializer.Deserialize(new StringReader(json), typeof(TestClass));
}
}
}
+2 -2
View File
@@ -177,10 +177,10 @@ namespace Newtonsoft.Json
/// Deserializes the Json structure contained by the specified <see cref="StringReader"/>
/// into an instance of the specified type.
/// </summary>
/// <param name="reader">The <see cref="JsonReader"/> containing the object.</param>
/// <param name="reader">The <see cref="TextReader"/> containing the object.</param>
/// <param name="objectType">The <see cref="Type"/> of object being deserialized.</param>
/// <returns>The instance of <paramref name="objectType"/> being deserialized.</returns>
public object Deserialize(StringReader reader, Type objectType)
public object Deserialize(TextReader reader, Type objectType)
{
return Deserialize(new JsonTextReader(reader), objectType);
}