code: @SuppressWarnings("unchecked")
      private JSONObject convertMapToJSONObject(Map map) throws IOException {
          Map newMap;
  
          // Only perform wrapping if it's enabled and the input map requires it.
          if (isWrapNestedMapsAndCollections && requiresWrap(map)) {
              newMap = new HashMap<String, Object>();
  
              // Iterate through the elements in the input map.
              for (Object key : map.keySet()) {
                  Object value = map.get(key);
                  Object newValue = value;
  
                  // Perform recursive conversions on maps and collections.
                  if (value instanceof Map) {
                      newValue = convertMapToJSONObject((Map) value);
                  } else if (value instanceof Collection) {
                      newValue = convertCollectionToJSONArray((Collection) value);
                  } else if (value instanceof Object[]) {
                      newValue = convertCollectionToJSONArray(Arrays.asList((Object[]) value));
                  }
  
                  // Add the value to the new map.
                  newMap.put(key, newValue);
              }
          } else {
              // Use the input map as-is.
              newMap = map;
          }
  
          // Pass the new map to the JSONObject constructor.
          return getJsonObjectManager().newObject(newMap);
      }
docs: Converts an input map to a JSONObject, wrapping any values in the map if wrapping is enabled
  and the map contains wrappable values (i.e. nested maps or collections).
  
  @param map The map to convert.
  @return A JSONObject representing the map.
  @throws IOException if there is an error creating the JSONObject.