#123 XMLSerialization for same XML generates different JSON

open
nobody
None
5
2011-09-19
2011-09-19
Anonymous
No

Hi,
the two tests below are identical except that in the second one we introduced some new lines characters in the XML.

In the second scenario the test fails: XMLSerializer.read() wrongly generates a JsonArray.

Thanks,
Ilias

@Test
public void GivenAnXmlWithOnlyOneElementShouldConvertItIntoJson() throws Exception {
String xmlString = "<member><gender>M</gender></member>";
XMLSerializer xmlSerializer = new XMLSerializer();

JSON read = xmlSerializer.read(xmlString);

Assert.assertEquals("{\"gender\":\"M\"}", read.toString());
}

@Test
public void GivenAnXmlWithOnlyOneElementAndNewLinesShouldConvertItIntoJson() throws Exception {
String xmlString = "<member>\n<gender>M</gender>\n</member>";
XMLSerializer xmlSerializer = new XMLSerializer();

JSON read = xmlSerializer.read(xmlString);

Assert.assertEquals("{\"gender\":\"M\"}", read.toString());
}

Discussion