-Added CheckAdditionalContent to JsonSerializer/JsonSerializerSettings

-Fixed bad JSON in an array with error handling creating an infinite loop
-JsonTextReader no longer returns no content after consecutive underlying content read failures
This commit is contained in:
James Newton-King
2012-05-17 15:27:26 +12:00
parent e47a0eab58
commit bdc73900b5
12 changed files with 182 additions and 79 deletions
@@ -6256,6 +6256,28 @@ Parameter name: value",
}", json);
}
#endif
[Test]
public void CheckAdditionalContent()
{
string json = "{one:1}{}";
JsonSerializerSettings settings = new JsonSerializerSettings();
JsonSerializer s = JsonSerializer.Create(settings);
IDictionary<string, int> o = s.Deserialize<Dictionary<string, int>>(new JsonTextReader(new StringReader(json)));
Assert.IsNotNull(o);
Assert.AreEqual(1, o["one"]);
settings.CheckAdditionalContent = true;
s = JsonSerializer.Create(settings);
ExceptionAssert.Throws<JsonReaderException>(
"Additional text encountered after finished reading JSON content: {. Path '', line 1, position 7.",
() =>
{
s.Deserialize<Dictionary<string, int>>(new JsonTextReader(new StringReader(json)));
});
}
}
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE)