Add line information to JsonSerializationException (#1829)
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user