@Test public void mapToJsonObject_forNull_returnsNull() { assertNull(StripeJsonUtils.mapToJsonObject(null)); }
@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) { } } 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) { } } return jsonObject; }
StripeJsonUtils { @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) { } } 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) { } } return jsonObject; } }
StripeJsonUtils { @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) { } } 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) { } } return jsonObject; }  }
StripeJsonUtils { @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) { } } 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) { } } return jsonObject; }   }
StripeJsonUtils { @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) { } } 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) { } } return jsonObject; }    }