-Fixed overflow when converting incomplete JSON to XML
This commit is contained in:
@@ -916,6 +916,16 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
Assert.AreEqual(doc.InnerXml, deserializedDoc.InnerXml);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FailOnIncomplete()
|
||||
{
|
||||
string json = @"{'Row' : ";
|
||||
|
||||
ExceptionAssert.Throws<JsonSerializationException>(
|
||||
() => JsonConvert.DeserializeXmlNode(json, "ROOT"),
|
||||
"Unexpected end when reading JSON. Path 'Row', line 1, position 9.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DocumentDeserialize()
|
||||
{
|
||||
|
||||
@@ -367,109 +367,6 @@ namespace Newtonsoft.Json.Tests.Schema
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateSchemaForDirectoryInfo()
|
||||
{
|
||||
JsonSchemaGenerator generator = new JsonSchemaGenerator();
|
||||
generator.UndefinedSchemaIdHandling = UndefinedSchemaIdHandling.UseTypeName;
|
||||
generator.ContractResolver = new CustomDirectoryInfoMapper
|
||||
{
|
||||
#if !(PORTABLE || DNXCORE50)
|
||||
IgnoreSerializableAttribute = true
|
||||
#endif
|
||||
};
|
||||
|
||||
JsonSchema schema = generator.Generate(typeof(DirectoryInfo), true);
|
||||
|
||||
string json = schema.ToString();
|
||||
|
||||
StringAssert.AreEqual(@"{
|
||||
""id"": ""System.IO.DirectoryInfo"",
|
||||
""required"": true,
|
||||
""type"": [
|
||||
""object"",
|
||||
""null""
|
||||
],
|
||||
""additionalProperties"": false,
|
||||
""properties"": {
|
||||
""Name"": {
|
||||
""required"": true,
|
||||
""type"": [
|
||||
""string"",
|
||||
""null""
|
||||
]
|
||||
},
|
||||
""Parent"": {
|
||||
""$ref"": ""System.IO.DirectoryInfo""
|
||||
},
|
||||
""Exists"": {
|
||||
""required"": true,
|
||||
""type"": ""boolean""
|
||||
},
|
||||
""FullName"": {
|
||||
""required"": true,
|
||||
""type"": [
|
||||
""string"",
|
||||
""null""
|
||||
]
|
||||
},
|
||||
""Extension"": {
|
||||
""required"": true,
|
||||
""type"": [
|
||||
""string"",
|
||||
""null""
|
||||
]
|
||||
},
|
||||
""CreationTime"": {
|
||||
""required"": true,
|
||||
""type"": ""string""
|
||||
},
|
||||
""CreationTimeUtc"": {
|
||||
""required"": true,
|
||||
""type"": ""string""
|
||||
},
|
||||
""LastAccessTime"": {
|
||||
""required"": true,
|
||||
""type"": ""string""
|
||||
},
|
||||
""LastAccessTimeUtc"": {
|
||||
""required"": true,
|
||||
""type"": ""string""
|
||||
},
|
||||
""LastWriteTime"": {
|
||||
""required"": true,
|
||||
""type"": ""string""
|
||||
},
|
||||
""LastWriteTimeUtc"": {
|
||||
""required"": true,
|
||||
""type"": ""string""
|
||||
},
|
||||
""Attributes"": {
|
||||
""required"": true,
|
||||
""type"": ""integer""
|
||||
}
|
||||
}
|
||||
}", json);
|
||||
|
||||
DirectoryInfo temp = new DirectoryInfo(@"c:\temp");
|
||||
|
||||
JTokenWriter jsonWriter = new JTokenWriter();
|
||||
JsonSerializer serializer = new JsonSerializer();
|
||||
serializer.Converters.Add(new IsoDateTimeConverter());
|
||||
serializer.ContractResolver = new CustomDirectoryInfoMapper
|
||||
{
|
||||
#if !(PORTABLE || DNXCORE50)
|
||||
IgnoreSerializableInterface = true
|
||||
#endif
|
||||
};
|
||||
serializer.Serialize(jsonWriter, temp);
|
||||
|
||||
List<string> errors = new List<string>();
|
||||
jsonWriter.Token.Validate(schema, (sender, args) => errors.Add(args.Message));
|
||||
|
||||
Assert.AreEqual(0, errors.Count);
|
||||
}
|
||||
#endif
|
||||
|
||||
[Test]
|
||||
|
||||
Reference in New Issue
Block a user