Upgrading from json.net 4.0.2 to 4.5.6, I found a very annoying behavior change.
A simple xml like below :
<root>
<Reports d1p1:Array="true" xmlns:d1p1="http://james.newtonking.com/projects/json" />
</root>
was converted (4.0.2) to :
{
"root": {
"Reports": []
}
}
and now (4.5.6) is converted to :
{
"root": {
"Reports": [{}]
}
}
We have now an empty object in the table whereas I expected to have an empty table.
The issue 20604 is the root of the problem.
The code below (version:4.5.6, file:XmlNodeConverter.cs, ligne:l.965):
if (IsArray(node) && node.ChildNodes.All(n => n.LocalName == node.LocalName) && node.ChildNodes.Count > 0) // added node.ChildNodes.Count > 0
should be replace by :
if (IsArray(node) && node.ChildNodes.All(n => n.LocalName == node.LocalName) && !HasUserAttribute(node)) // add function HasUserAttribute
function HasUserAttribute :
private bool HasUserAttribute(IXmlNode node)
{
foreach (IXmlNode attribute in node.Attributes)
{
if (attribute.LocalName != "Array" && attribute.Value != JsonNamespaceUri)
{
return true;
}
}
return false;
}