code: @Nullable
      @SuppressWarnings("unchecked")
      static JSONObject mapToJsonObject(@Nullable Map<String, ? extends Object> mapObject) {
          if (mapObject == null) {
              return null;
          }
          JSONObject jsonObject = new JSONObject();
          for (String key : mapObject.keySet()) {
              Object value = mapObject.get(key);
              if (value == null) {
                  continue;
              }
  
              try {
                  if (value instanceof Map<?, ?>) {
                      try {
                          Map<String, Object> mapValue = (Map<String, Object>) value;
                          jsonObject.put(key, mapToJsonObject(mapValue));
                      } catch (ClassCastException classCastException) {
                          // We don't include the item in the JSONObject if the keys are not Strings.
                      }
                  } else if (value instanceof List<?>) {
                      jsonObject.put(key, listToJsonArray((List<Object>) value));
                  } else if (value instanceof Number || value instanceof Boolean) {
                      jsonObject.put(key, value);
                  } else {
                      jsonObject.put(key, value.toString());
                  }
              } catch (JSONException jsonException) {
                  // Simply skip this value
              }
          }
          return jsonObject;
      }
docs: Converts a string-keyed {@link Map} into a {@link JSONObject}. This will cause a
  {@link ClassCastException} if any sub-map has keys that are not {@link String Strings}.
  
  @param mapObject the {@link Map} that you'd like in JSON form
  @return a {@link JSONObject} representing the input map, or {@code null} if the input
  object is {@code null}