@@ -976,6 +976,45 @@ public void testLongForceList() {
976976 Util .compareActualVsExpectedJsonObjects (jsonObject , expetedJsonObject );
977977 }
978978 @ Test
979+ public void testMultipleTagForceList () {
980+ String xmlStr =
981+ "<addresses>\n " +
982+ " <address>\n " +
983+ " <name>Sherlock Holmes</name>\n " +
984+ " <name>John H. Watson</name>\n " +
985+ " </address>\n " +
986+ "</addresses>" ;
987+
988+ String expectedStr =
989+ "{" +
990+ "\" addresses\" :[" +
991+ "{" +
992+ "\" address\" :[" +
993+ "{" +
994+ "\" name\" :[" +
995+ "\" Sherlock Holmes\" ," +
996+ "\" John H. Watson\" " +
997+ "]" +
998+ "}" +
999+ "]" +
1000+ "}" +
1001+ "]" +
1002+ "}" ;
1003+
1004+ Set <String > forceList = new HashSet <String >();
1005+ forceList .add ("addresses" );
1006+ forceList .add ("address" );
1007+ forceList .add ("name" );
1008+
1009+ XMLParserConfiguration config =
1010+ new XMLParserConfiguration ()
1011+ .withForceList (forceList );
1012+ JSONObject jsonObject = XML .toJSONObject (xmlStr , config );
1013+ JSONObject expetedJsonObject = new JSONObject (expectedStr );
1014+
1015+ Util .compareActualVsExpectedJsonObjects (jsonObject , expetedJsonObject );
1016+ }
1017+ @ Test
9791018 public void testEmptyForceList () {
9801019 String xmlStr =
9811020 "<addresses></addresses>" ;
@@ -994,6 +1033,44 @@ public void testEmptyForceList() {
9941033
9951034 Util .compareActualVsExpectedJsonObjects (jsonObject , expetedJsonObject );
9961035 }
1036+ @ Test
1037+ public void testContentForceList () {
1038+ String xmlStr =
1039+ "<addresses>Baker Street</addresses>" ;
1040+
1041+ String expectedStr =
1042+ "{\" addresses\" :[\" Baker Street\" ]}" ;
1043+
1044+ Set <String > forceList = new HashSet <String >();
1045+ forceList .add ("addresses" );
1046+
1047+ XMLParserConfiguration config =
1048+ new XMLParserConfiguration ()
1049+ .withForceList (forceList );
1050+ JSONObject jsonObject = XML .toJSONObject (xmlStr , config );
1051+ JSONObject expetedJsonObject = new JSONObject (expectedStr );
1052+
1053+ Util .compareActualVsExpectedJsonObjects (jsonObject , expetedJsonObject );
1054+ }
1055+ @ Test
1056+ public void testEmptyTagForceList () {
1057+ String xmlStr =
1058+ "<addresses />" ;
1059+
1060+ String expectedStr =
1061+ "{\" addresses\" :[]}" ;
1062+
1063+ Set <String > forceList = new HashSet <String >();
1064+ forceList .add ("addresses" );
1065+
1066+ XMLParserConfiguration config =
1067+ new XMLParserConfiguration ()
1068+ .withForceList (forceList );
1069+ JSONObject jsonObject = XML .toJSONObject (xmlStr , config );
1070+ JSONObject expetedJsonObject = new JSONObject (expectedStr );
1071+
1072+ Util .compareActualVsExpectedJsonObjects (jsonObject , expetedJsonObject );
1073+ }
9971074
9981075 /**
9991076 * Convenience method, given an input string and expected result,
0 commit comments