-Improved error when attempting to convert root JSON object property to an XML attribute

This commit is contained in:
James Newton-King
2016-10-25 14:43:27 +13:00
parent 0e0918b143
commit 29c84fd7c2
2 changed files with 37 additions and 3 deletions
@@ -2701,6 +2701,35 @@ namespace Newtonsoft.Json.Tests.Converters
Assert.AreEqual(json, json2);
}
[Test]
public void RootPropertyError()
{
string json = @"{
""$id"": ""1"",
""AOSLocaleName"": ""en-US"",
""AXLanguage"": ""EN-AU"",
""Company"": ""AURE"",
""CompanyTimeZone"": 8,
""CurrencyInfo"": {
""$id"": ""2"",
""CurrencyCode"": ""AUD"",
""Description"": ""Australian Dollar"",
""ExchangeRate"": 100.0,
""ISOCurrencyCode"": ""AUD"",
""Prefix"": """",
""Suffix"": """"
},
""IsSysAdmin"": true,
""UserId"": ""lamar.miller"",
""UserPreferredCalendar"": 0,
""UserPreferredTimeZone"": 8
}";
ExceptionAssert.Throws<JsonSerializationException>(
() => JsonConvert.DeserializeXmlNode(json),
"JSON root object has property '$id' that will be converted to an attribute. A root object cannot have any attribute properties. Consider specifing a DeserializeRootElementName. Path '$id', line 2, position 12.");
}
[Test]
public void SerializeEmptyNodeAndOmitRoot()
{