-Improved error when attempting to convert root JSON object property to an XML attribute
This commit is contained in:
@@ -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()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user