@@ -1033,4 +1033,39 @@ public void testToJsonWithXSITypeWhenTypeConversionEnabled() {
10331033 Util .compareActualVsExpectedJsonObjects (actualJson ,expectedJson );
10341034 }
10351035
1036+ @ Test
1037+ public void testToJsonWithXSITypeWhenTypeConversionNotEnabledOnOne () {
1038+ String originalXml = "<root><asString xsi:type=\" string\" >12345</asString><asInt>54321</asInt></root>" ;
1039+ String expectedJsonString = "{\" root\" :{\" asString\" :\" 12345\" ,\" asInt\" :54321}}" ;
1040+ JSONObject expectedJson = new JSONObject (expectedJsonString );
1041+ Map <String , XMLXsiTypeConverter <?>> xsiTypeMap = new HashMap <String , XMLXsiTypeConverter <?>>();
1042+ xsiTypeMap .put ("string" , new XMLXsiTypeConverter <String >() {
1043+ @ Override public String convert (final String value ) {
1044+ return value ;
1045+ }
1046+ });
1047+ JSONObject actualJson = XML .toJSONObject (originalXml , new XMLParserConfiguration ().withXsiTypeMap (xsiTypeMap ));
1048+ Util .compareActualVsExpectedJsonObjects (actualJson ,expectedJson );
1049+ }
1050+
1051+ @ Test
1052+ public void testXSITypeMapNotModifiable () {
1053+ Map <String , XMLXsiTypeConverter <?>> xsiTypeMap = new HashMap <String , XMLXsiTypeConverter <?>>();
1054+ XMLParserConfiguration config = new XMLParserConfiguration ().withXsiTypeMap (xsiTypeMap );
1055+ xsiTypeMap .put ("string" , new XMLXsiTypeConverter <String >() {
1056+ @ Override public String convert (final String value ) {
1057+ return value ;
1058+ }
1059+ });
1060+ assertEquals ("Config Conversion Map size is expected to be 0" , 0 , config .getXsiTypeMap ().size ());
1061+
1062+ try {
1063+ config .getXsiTypeMap ().put ("boolean" , new XMLXsiTypeConverter <Boolean >() {
1064+ @ Override public Boolean convert (final String value ) {
1065+ return Boolean .valueOf (value );
1066+ }
1067+ });
1068+ fail ("Expected to be unable to modify the config" );
1069+ } catch (Exception ignored ) { }
1070+ }
10361071}
0 commit comments