mirror of
https://github.com/fankes/JSON-java-compat.git
synced 2025-09-08 03:24:27 +08:00
#748 - close XML tag explicitly for empty tags with configuration.
This commit is contained in:
@@ -1177,6 +1177,26 @@ public class XMLTest {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCreateExplicitEndTagWithEmptyValueWhenConfigured(){
|
||||
String jsonString = "{outer:{innerOne:\"\", innerTwo:\"two\"}}";
|
||||
JSONObject jsonObject = new JSONObject(jsonString);
|
||||
String expectedXmlString = "<encloser><outer><innerOne></innerOne><innerTwo>two</innerTwo></outer></encloser>";
|
||||
String xmlForm = XML.toString(jsonObject,"encloser", new XMLParserConfiguration().withCloseEmptyTag(true));
|
||||
assertEquals(expectedXmlString, xmlForm);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotCreateExplicitEndTagWithEmptyValueWhenNotConfigured(){
|
||||
String jsonString = "{outer:{innerOne:\"\", innerTwo:\"two\"}}";
|
||||
JSONObject jsonObject = new JSONObject(jsonString);
|
||||
String expectedXmlString = "<encloser><outer><innerOne/><innerTwo>two</innerTwo></outer></encloser>";
|
||||
String xmlForm = XML.toString(jsonObject,"encloser", new XMLParserConfiguration().withCloseEmptyTag(false));
|
||||
assertEquals(expectedXmlString, xmlForm);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testIndentSimpleJsonObject(){
|
||||
String str = "{ \"employee\": { \n" +
|
||||
|
Reference in New Issue
Block a user