I'm using net.sf.json.xml.XMLSerializer to convert XML documents to JSON. I'm getting two different results for almost two similar XML documents. My code is:
public static void main(String[] args) throws DocumentException {
String t1="<A><B>aa</B><C><D>Martin Ritt</D> </C></A>";
String t2="<A><B>aa</B><C><D>Martin Ritt</D></C></A>";
System.out.println(new XMLSerializer().read(t1).toString());
System.out.println(new XMLSerializer().read(t2).toString());
}
The first string t1 is converted to:
{"B":"aa","C":["Martin Ritt"]}
while t2 is converted to:
{"B":"aa","C":{"D":"Martin Ritt"}}
That means, in the first case, C is considered an array while in the second case, it is considered an object. The difference between the two XMLs is the space after the closing of the D element. That is, after </D>
.
Any idea what is going on here? what is the rule? I'm more interested in how to make it recognize arrays consistently.