@@ -775,8 +775,8 @@ public void testToJSONArray_jsonOutput() {
775775 */
776776 @ Test
777777 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}}" );
780780 final JSONObject actualJsonOutput = XML .toJSONObject (originalXml ,
781781 new XMLParserConfiguration ().withKeepNumberAsString (true ));
782782 Util .compareActualVsExpectedJsonObjects (actualJsonOutput ,expected );
@@ -787,13 +787,25 @@ public void testToJSONArray_jsonOutput_withKeepNumberAsString() {
787787 */
788788 @ Test
789789 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\" }}" );
792792 final JSONObject actualJsonOutput = XML .toJSONObject (originalXml ,
793793 new XMLParserConfiguration ().withKeepBooleanAsString (true ));
794794 Util .compareActualVsExpectedJsonObjects (actualJsonOutput ,expected );
795795 }
796796
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+
797809 /**
798810 * Test keepStrings behavior when setting keepBooleanAsString, keepNumberAsString
799811 */
0 commit comments