@@ -775,8 +775,8 @@ public void testToJSONArray_jsonOutput() {
775
775
*/
776
776
@ Test
777
777
public void testToJSONArray_jsonOutput_withKeepNumberAsString () {
778
- final String originalXml = "<root><id>01</id><id>1</id><id>00</id><id>0</id><item id=\" 01\" /><title>True</title></root>" ;
779
- final JSONObject expected = new JSONObject ("{\" root\" :{\" item\" :{\" id\" :\" 01\" },\" id\" :[\" 01\" ,\" 1\" ,\" 00\" ,\" 0\" ],\" title\" :true}}" );
778
+ final String originalXml = "<root><id>01</id><id>1</id><id>00</id><id>0</id><id>null</id>< item id=\" 01\" /><title>True</title></root>" ;
779
+ final JSONObject expected = new JSONObject ("{\" root\" :{\" item\" :{\" id\" :\" 01\" },\" id\" :[\" 01\" ,\" 1\" ,\" 00\" ,\" 0\" ,null ],\" title\" :true}}" );
780
780
final JSONObject actualJsonOutput = XML .toJSONObject (originalXml ,
781
781
new XMLParserConfiguration ().withKeepNumberAsString (true ));
782
782
Util .compareActualVsExpectedJsonObjects (actualJsonOutput ,expected );
@@ -787,13 +787,25 @@ public void testToJSONArray_jsonOutput_withKeepNumberAsString() {
787
787
*/
788
788
@ Test
789
789
public void testToJSONArray_jsonOutput_withKeepBooleanAsString () {
790
- final String originalXml = "<root><id>01</id><id>1</id><id>00</id><id>0</id><item id=\" 01\" /><title>True</title></root>" ;
791
- final JSONObject expected = new JSONObject ("{\" root\" :{\" item\" :{\" id\" :\" 01\" },\" id\" :[\" 01\" ,1,\" 00\" ,0],\" title\" :\" True\" }}" );
790
+ final String originalXml = "<root><id>01</id><id>1</id><id>00</id><id>0</id><id>null</id>< item id=\" 01\" /><title>True</title></root>" ;
791
+ final JSONObject expected = new JSONObject ("{\" root\" :{\" item\" :{\" id\" :\" 01\" },\" id\" :[\" 01\" ,1,\" 00\" ,0,null ],\" title\" :\" True\" }}" );
792
792
final JSONObject actualJsonOutput = XML .toJSONObject (originalXml ,
793
793
new XMLParserConfiguration ().withKeepBooleanAsString (true ));
794
794
Util .compareActualVsExpectedJsonObjects (actualJsonOutput ,expected );
795
795
}
796
796
797
+ /**
798
+ * null is "null" when keepStrings == true
799
+ */
800
+ @ Test
801
+ public void testToJSONArray_jsonOutput_null_withKeepString () {
802
+ final String originalXml = "<root><id>01</id><id>1</id><id>00</id><id>0</id><item id=\" 01\" /><title>null</title></root>" ;
803
+ final JSONObject expected = new JSONObject ("{\" root\" :{\" item\" :{\" id\" :\" 01\" },\" id\" :[\" 01\" ,\" 1\" ,\" 00\" ,\" 0\" ],\" title\" :\" null\" }}" );
804
+ final JSONObject actualJsonOutput = XML .toJSONObject (originalXml ,
805
+ new XMLParserConfiguration ().withKeepStrings (true ));
806
+ Util .compareActualVsExpectedJsonObjects (actualJsonOutput ,expected );
807
+ }
808
+
797
809
/**
798
810
* Test keepStrings behavior when setting keepBooleanAsString, keepNumberAsString
799
811
*/
0 commit comments