code: @SuppressWarnings("unchecked")
      private JSONArray convertCollectionToJSONArray(Collection collection) throws IOException {
          Collection newCollection;
  
          // Only perform wrapping if it's enabled and the input collection requires it.
          if (isWrapNestedMapsAndCollections && requiresWrap(collection)) {
              newCollection = new ArrayList<Object>();
  
              // Iterate through the elements in the input map.
              for (Object value : collection) {
                  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);
                  }
  
                  // Add the value to the new collection.
                  newCollection.add(newValue);
              }
          } else {
              // Use the input collection as-is.
              newCollection = collection;
          }
  
          // Pass the new collection to the JSONArray constructor.
          return getJsonObjectManager().newArray(newCollection);
      }
docs: Converts an input collection to a JSONArray, wrapping any values in the collection if
  wrapping is enabled and the collection contains wrappable values (i.e. maps or nested
  collections).
  
  @param collection The collection to convert.
  @return A JSONArray representing the collection.
  @throws IOException if there is an error creating the JSONArray.