Update initialDepth for error handling (#1550)
* Fix target depth when skipping over handled errors Keep reading until the reader reaches the initial depth rather than initial depth + 1 * Fix the initialDepth when handling errors in lists The initialDepth should be +1 when handling deserialization errors in lists and arrays in order to not skip subsequent items * Add unit tests for dictionary error handling Ignoring errors in dictionary object by completely removing the bad items from the dictionary
This commit is contained in:
committed by
James Newton-King
parent
69640e88d8
commit
e5e901c6d0
@@ -1474,7 +1474,7 @@ namespace Newtonsoft.Json.Serialization
|
||||
|
||||
if (IsErrorHandled(list, contract, errorPosition.Position, reader as IJsonLineInfo, reader.Path, ex))
|
||||
{
|
||||
HandleError(reader, true, initialDepth);
|
||||
HandleError(reader, true, initialDepth + 1);
|
||||
|
||||
if (previousErrorIndex != null && previousErrorIndex == errorPosition.Position)
|
||||
{
|
||||
@@ -1628,7 +1628,7 @@ namespace Newtonsoft.Json.Serialization
|
||||
|
||||
if (IsErrorHandled(underlyingList, contract, errorPosition.Position, reader as IJsonLineInfo, reader.Path, ex))
|
||||
{
|
||||
HandleError(reader, true, initialDepth);
|
||||
HandleError(reader, true, initialDepth + 1);
|
||||
|
||||
if (previousErrorIndex != null && previousErrorIndex == errorPosition.Position)
|
||||
{
|
||||
@@ -2338,7 +2338,7 @@ namespace Newtonsoft.Json.Serialization
|
||||
{
|
||||
if (IsErrorHandled(newObject, contract, memberName, reader as IJsonLineInfo, reader.Path, ex))
|
||||
{
|
||||
HandleError(reader, true, initialDepth - 1);
|
||||
HandleError(reader, true, initialDepth);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2535,7 +2535,7 @@ namespace Newtonsoft.Json.Serialization
|
||||
{
|
||||
reader.Skip();
|
||||
|
||||
while (reader.Depth > (initialDepth + 1))
|
||||
while (reader.Depth > initialDepth)
|
||||
{
|
||||
if (!reader.Read())
|
||||
{
|
||||
@@ -2545,4 +2545,4 @@ namespace Newtonsoft.Json.Serialization
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user