@Test public void stringHashToJsonObject_returnsExpectedObject() { Map<String, String> stringHash = new HashMap<>(); stringHash.put("akey", "avalue"); stringHash.put("bkey", "bvalue"); stringHash.put("ckey", "cvalue"); stringHash.put("dkey", "dvalue"); try { JSONObject expectedObject = new JSONObject(SIMPLE_JSON_HASH_OBJECT); JsonTestUtils.assertJsonEquals(expectedObject, StripeJsonUtils.stringHashToJsonObject(stringHash)); } catch (JSONException jsonException) { fail("Test data failure " + jsonException.getLocalizedMessage()); } }
@Nullable static JSONObject stringHashToJsonObject(@Nullable Map<String, String> stringStringMap) { if (stringStringMap == null) { return null; } JSONObject jsonObject = new JSONObject(); for (String key : stringStringMap.keySet()) { try { jsonObject.put(key, stringStringMap.get(key)); } catch (JSONException jsonException) { } } return jsonObject; }
StripeJsonUtils { @Nullable static JSONObject stringHashToJsonObject(@Nullable Map<String, String> stringStringMap) { if (stringStringMap == null) { return null; } JSONObject jsonObject = new JSONObject(); for (String key : stringStringMap.keySet()) { try { jsonObject.put(key, stringStringMap.get(key)); } catch (JSONException jsonException) { } } return jsonObject; } }
StripeJsonUtils { @Nullable static JSONObject stringHashToJsonObject(@Nullable Map<String, String> stringStringMap) { if (stringStringMap == null) { return null; } JSONObject jsonObject = new JSONObject(); for (String key : stringStringMap.keySet()) { try { jsonObject.put(key, stringStringMap.get(key)); } catch (JSONException jsonException) { } } return jsonObject; }  }
StripeJsonUtils { @Nullable static JSONObject stringHashToJsonObject(@Nullable Map<String, String> stringStringMap) { if (stringStringMap == null) { return null; } JSONObject jsonObject = new JSONObject(); for (String key : stringStringMap.keySet()) { try { jsonObject.put(key, stringStringMap.get(key)); } catch (JSONException jsonException) { } } return jsonObject; }   }
StripeJsonUtils { @Nullable static JSONObject stringHashToJsonObject(@Nullable Map<String, String> stringStringMap) { if (stringStringMap == null) { return null; } JSONObject jsonObject = new JSONObject(); for (String key : stringStringMap.keySet()) { try { jsonObject.put(key, stringStringMap.get(key)); } catch (JSONException jsonException) { } } return jsonObject; }    }