@Test public void putAdditionalFieldsIntoJsonObject_whenNoFieldsArePassed_doesNothing() { JSONObject jsonObject = new JSONObject(); try { jsonObject.put("a", "a_value"); } catch (JSONException unexpected) { fail("Unexpected error: " + unexpected.getLocalizedMessage()); } Map<String, Object> emptyMap = new HashMap<>(); putAdditionalFieldsIntoJsonObject(jsonObject, emptyMap); assertEquals(1, jsonObject.length()); }
static void putAdditionalFieldsIntoJsonObject( @Nullable JSONObject jsonObject, @Nullable Map<String, Object> additionalFields) { if (jsonObject == null || additionalFields == null || additionalFields.isEmpty()) { return; } for (String key : additionalFields.keySet()) { try { if (additionalFields.get(key) != null) { jsonObject.put(key, additionalFields.get(key)); } } catch (JSONException ignored) { } } }
StripeSourceTypeModel extends StripeJsonModel { static void putAdditionalFieldsIntoJsonObject( @Nullable JSONObject jsonObject, @Nullable Map<String, Object> additionalFields) { if (jsonObject == null || additionalFields == null || additionalFields.isEmpty()) { return; } for (String key : additionalFields.keySet()) { try { if (additionalFields.get(key) != null) { jsonObject.put(key, additionalFields.get(key)); } } catch (JSONException ignored) { } } } }
StripeSourceTypeModel extends StripeJsonModel { static void putAdditionalFieldsIntoJsonObject( @Nullable JSONObject jsonObject, @Nullable Map<String, Object> additionalFields) { if (jsonObject == null || additionalFields == null || additionalFields.isEmpty()) { return; } for (String key : additionalFields.keySet()) { try { if (additionalFields.get(key) != null) { jsonObject.put(key, additionalFields.get(key)); } } catch (JSONException ignored) { } } } StripeSourceTypeModel(); }
StripeSourceTypeModel extends StripeJsonModel { static void putAdditionalFieldsIntoJsonObject( @Nullable JSONObject jsonObject, @Nullable Map<String, Object> additionalFields) { if (jsonObject == null || additionalFields == null || additionalFields.isEmpty()) { return; } for (String key : additionalFields.keySet()) { try { if (additionalFields.get(key) != null) { jsonObject.put(key, additionalFields.get(key)); } } catch (JSONException ignored) { } } } StripeSourceTypeModel(); @NonNull Map<String, Object> getAdditionalFields(); }
StripeSourceTypeModel extends StripeJsonModel { static void putAdditionalFieldsIntoJsonObject( @Nullable JSONObject jsonObject, @Nullable Map<String, Object> additionalFields) { if (jsonObject == null || additionalFields == null || additionalFields.isEmpty()) { return; } for (String key : additionalFields.keySet()) { try { if (additionalFields.get(key) != null) { jsonObject.put(key, additionalFields.get(key)); } } catch (JSONException ignored) { } } } StripeSourceTypeModel(); @NonNull Map<String, Object> getAdditionalFields();  }