Skip to content

Commit 614e835

Browse files
committed
add test for xsi:nil to null conversion
1 parent 437ce10 commit 614e835

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/test/java/org/json/junit/XMLTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.json.JSONException;
1818
import org.json.JSONObject;
1919
import org.json.XML;
20+
import org.json.XMLParserConfiguration;
2021
import org.junit.Rule;
2122
import org.junit.Test;
2223
import org.junit.rules.TemporaryFolder;
@@ -856,4 +857,15 @@ public void testUnescape() {
856857

857858
}
858859

860+
/**
861+
* test passes when xsi:nil="true" converting to null (JSON specification-like conversion)
862+
*/
863+
@Test
864+
public void testToJsonWithNull() {
865+
final String originalXml = "<root><id xsi:nil=\"true\"/></root>";
866+
final String expectedJsonString = "{\"root\":{\"id\":null}}";
867+
868+
final JSONObject json = XML.toJSONObject(originalXml,new XMLParserConfiguration(false, "content", true));
869+
assertEquals(expectedJsonString, json.toString());
870+
}
859871
}

0 commit comments

Comments
 (0)