@Test public void putAdditionalFieldsIntoJsonObject_whenHasDuplicateFields_putsThemIntoObject() { JSONObject jsonObject = new JSONObject(); try { jsonObject.put("a_key", "original"); } catch (JSONException unexpected) { fail("Unexpected exception: " + unexpected); } Map<String, Object> additionalFields = new HashMap<>(); additionalFields.put("a_key", "a_value"); additionalFields.put("b_key", "b_value"); putAdditionalFieldsIntoJsonObject(jsonObject, additionalFields); assertEquals(2, jsonObject.length()); assertEquals("a_value", jsonObject.optString("a_key")); assertEquals("b_value", jsonObject.optString("b_key")); }
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();  }