Open jhorbulyk opened 4 years ago
In general I agree with you, having things shift is not nice at all. What would you expect to happen in this check if there is more than one key though?
What would you expect to happen in this check if there is more than one key though?
I would expect an error to be thrown.
Consider the following example code:
This results in the following output:
Observe that when XML is built from an object with a single key, that single key becomes the root of the XML object. However, when XML is built from an object with multiple keys, an implicit
<root>
tag is added. As far as I can tell, options such asexplicitRoot
do not alter this behavior.I find the above behavior problematic as it causes the locations of elements in the resulting XML to shift based on the number of elements in the incoming object. The output is also odd if input is somehing that isn't an object in JSON.
I understand that XML documents must have a single root/global element. Would it perhaps make sense to add some checks to ensure that the input being converted is an object and has ~at most~ exactly one key ~(excluding keys
charkey
andattrkey
)~?