-Fixed not erroring when deserializing incomplete JSON with a parameterized constructor

This commit is contained in:
James Newton-King
2016-10-24 14:20:59 +13:00
parent 570a7ca078
commit 0721bd4dec
2 changed files with 29 additions and 0 deletions
@@ -9753,6 +9753,14 @@ Path '', line 1, position 1.");
}
}
#endif
[Test]
public void ParametrizedConstructor_IncompleteJson()
{
string s = @"{""text"":""s"",""cursorPosition"":189,""dataSource"":""json_northwind"",";
ExceptionAssert.Throws<JsonSerializationException>(() => JsonConvert.DeserializeObject<CompletionDataRequest>(s), "Unexpected end when deserializing object. Path 'dataSource', line 1, position 63.");
}
}
public class DerivedWithPrivate : BaseWithPrivate
@@ -9912,4 +9920,20 @@ Path '', line 1, position 1.");
z = 3;
}
}
public class CompletionDataRequest
{
public CompletionDataRequest(string text, int cursorPosition, string dataSource, string project)
{
Text = text;
CursorPosition = cursorPosition;
DataSource = dataSource;
Project = project;
}
public string Text { get; }
public int CursorPosition { get; }
public string DataSource { get; }
public string Project { get; }
}
}
@@ -2194,6 +2194,11 @@ namespace Newtonsoft.Json.Serialization
}
} while (!exit && reader.Read());
if (!exit)
{
ThrowUnexpectedEndException(reader, contract, null, "Unexpected end when deserializing object.");
}
return propertyValues;
}