When converting JSON to XML encode characters in JSON property names which are not compatible with XML and decode when converting back.

This commit is contained in:
Oleg Deribas
2015-12-05 20:09:03 +00:00
parent c96779dc10
commit 7ce78833f4
2 changed files with 16 additions and 3 deletions
@@ -2554,6 +2554,19 @@ namespace Newtonsoft.Json.Tests.Converters
Assert.AreEqual(@"{""DocumentId"":""13779965364495889899""}", json2);
}
#endif
[Test]
public void DeserializeXmlIncompatibleCharsInPropertyName()
{
var json = "{\"%name\":\"value\"}";
XmlDocument node = JsonConvert.DeserializeXmlNode(json);
Assert.AreEqual("<_x0025_name>value</_x0025_name>", node.OuterXml);
string json2 = JsonConvert.SerializeXmlNode(node);
Assert.AreEqual(json, json2);
}
[Test]
public void SerializeEmptyNodeAndOmitRoot()