1
0
Fork 0
mirror of https://github.com/ethauvin/JSON-java.git synced 2025-06-17 07:50:52 -07:00

add test for xsi:nil to null conversion disabled

This commit is contained in:
meiskalt7 2019-04-21 00:53:39 +07:00
parent 614e8359b9
commit fa173fa51a

View file

@ -858,14 +858,26 @@ public class XMLTest {
} }
/** /**
* test passes when xsi:nil="true" converting to null (JSON specification-like conversion) * test passes when xsi:nil="true" converting to null (JSON specification-like nil conversion enabled)
*/ */
@Test @Test
public void testToJsonWithNull() { public void testToJsonWithNullWhenNilConversionEnabled() {
final String originalXml = "<root><id xsi:nil=\"true\"/></root>"; final String originalXml = "<root><id xsi:nil=\"true\"/></root>";
final String expectedJsonString = "{\"root\":{\"id\":null}}"; final String expectedJsonString = "{\"root\":{\"id\":null}}";
final JSONObject json = XML.toJSONObject(originalXml,new XMLParserConfiguration(false, "content", true)); final JSONObject json = XML.toJSONObject(originalXml, new XMLParserConfiguration(false, "content", true));
assertEquals(expectedJsonString, json.toString());
}
/**
* test passes when xsi:nil="true" not converting to null (JSON specification-like nil conversion disabled)
*/
@Test
public void testToJsonWithNullWhenNilConversionDisabled() {
final String originalXml = "<root><id xsi:nil=\"true\"/></root>";
final String expectedJsonString = "{\"root\":{\"id\":{\"xsi:nil\":true}}}";
final JSONObject json = XML.toJSONObject(originalXml, new XMLParserConfiguration());
assertEquals(expectedJsonString, json.toString()); assertEquals(expectedJsonString, json.toString());
} }
} }