code: @Nullable
      @SuppressWarnings("unchecked")
      static JSONArray listToJsonArray(@Nullable List values) {
          if (values == null) {
              return null;
          }
  
          JSONArray jsonArray = new JSONArray();
          for (Object object : values) {
              if (object instanceof Map<?, ?>) {
                  try {
                      Map<String, Object> mapObject = (Map<String, Object>) object;
                      jsonArray.put(mapToJsonObject(mapObject));
                  } catch (ClassCastException classCastException) {
                      // We don't include the item in the array if the keys are not Strings.
                  }
              } else if (object instanceof List<?>) {
                  jsonArray.put(listToJsonArray((List) object));
              } else if (object instanceof Number || object instanceof Boolean) {
                  jsonArray.put(object);
              } else {
                  jsonArray.put(object.toString());
              }
          }
          return jsonArray;
      }
docs: Converts a {@link List} into a {@link JSONArray}. A {@link ClassCastException} will be
  thrown if any object in the list (or any sub-list or sub-map) is a {@link Map} whose keys
  are not {@link String Strings}.
  
  @param values a {@link List} of values to be put in a {@link JSONArray}
  @return a {@link JSONArray}, or {@code null} if the input was {@code null}