Skip to content

Commit fa173fa

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

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -858,14 +858,26 @@ public void testUnescape() {
858858
}
859859

860860
/**
861-
* test passes when xsi:nil="true" converting to null (JSON specification-like conversion)
861+
* test passes when xsi:nil="true" converting to null (JSON specification-like nil conversion enabled)
862862
*/
863863
@Test
864-
public void testToJsonWithNull() {
864+
public void testToJsonWithNullWhenNilConversionEnabled() {
865865
final String originalXml = "<root><id xsi:nil=\"true\"/></root>";
866866
final String expectedJsonString = "{\"root\":{\"id\":null}}";
867867

868-
final JSONObject json = XML.toJSONObject(originalXml,new XMLParserConfiguration(false, "content", true));
868+
final JSONObject json = XML.toJSONObject(originalXml, new XMLParserConfiguration(false, "content", true));
869+
assertEquals(expectedJsonString, json.toString());
870+
}
871+
872+
/**
873+
* test passes when xsi:nil="true" not converting to null (JSON specification-like nil conversion disabled)
874+
*/
875+
@Test
876+
public void testToJsonWithNullWhenNilConversionDisabled() {
877+
final String originalXml = "<root><id xsi:nil=\"true\"/></root>";
878+
final String expectedJsonString = "{\"root\":{\"id\":{\"xsi:nil\":true}}}";
879+
880+
final JSONObject json = XML.toJSONObject(originalXml, new XMLParserConfiguration());
869881
assertEquals(expectedJsonString, json.toString());
870882
}
871883
}

0 commit comments

Comments
 (0)