Add line information to JsonSerializationException (#1829)

This commit is contained in:
James Newton-King
2018-09-16 14:10:33 -07:00
committed by GitHub
parent c7d1615191
commit d7150871cb
3 changed files with 59 additions and 3 deletions
@@ -45,7 +45,11 @@ namespace Newtonsoft.Json.Tests.Converters
[Test]
public void DeserializeInvalidDataTable()
{
ExceptionAssert.Throws<JsonException>(() => JsonConvert.DeserializeObject<DataSet>("{\"pending_count\":23,\"completed_count\":45}"), "Unexpected JSON token when reading DataTable. Expected StartArray, got Integer. Path 'pending_count', line 1, position 19.");
var ex = ExceptionAssert.Throws<JsonSerializationException>(() => JsonConvert.DeserializeObject<DataSet>("{\"pending_count\":23,\"completed_count\":45}"), "Unexpected JSON token when reading DataTable. Expected StartArray, got Integer. Path 'pending_count', line 1, position 19.");
Assert.AreEqual(1, ex.LineNumber);
Assert.AreEqual(19, ex.LinePosition);
Assert.AreEqual("pending_count", ex.Path);
}
[Test]
+5 -1
View File
@@ -121,13 +121,17 @@ namespace Newtonsoft.Json.Tests
[Test]
public void PopulateObjectWithOnlyComment()
{
ExceptionAssert.Throws<JsonSerializationException>(() =>
var ex = ExceptionAssert.Throws<JsonSerializationException>(() =>
{
string json = @"// file header";
PopulateTestObject o = new PopulateTestObject();
JsonConvert.PopulateObject(json, o);
}, "No JSON content found. Path '', line 1, position 14.");
Assert.AreEqual(1, ex.LineNumber);
Assert.AreEqual(14, ex.LinePosition);
Assert.AreEqual(string.Empty, ex.Path);
}
[Test]