@Test public void removeNullAndEmptyParams_removesNestedEmptyParams() { Map<String, Object> testMap = new HashMap<>(); Map<String, Object> firstNestedMap = new HashMap<>(); Map<String, Object> secondNestedMap = new HashMap<>(); testMap.put("a", "fun param"); testMap.put("b", "not null"); firstNestedMap.put("1a", "something"); firstNestedMap.put("1b", null); secondNestedMap.put("2a", ""); secondNestedMap.put("2b", "hello world"); firstNestedMap.put("1c", secondNestedMap); testMap.put("c", firstNestedMap); StripeNetworkUtils.removeNullAndEmptyParams(testMap); assertEquals(3, testMap.size()); assertTrue(testMap.containsKey("a")); assertTrue(testMap.containsKey("b")); assertTrue(testMap.containsKey("c")); assertEquals(2, firstNestedMap.size()); assertTrue(firstNestedMap.containsKey("1a")); assertTrue(firstNestedMap.containsKey("1c")); assertEquals(1, secondNestedMap.size()); assertTrue(secondNestedMap.containsKey("2b")); }
@SuppressWarnings("unchecked") public static void removeNullAndEmptyParams(@NonNull Map<String, Object> mapToEdit) { for (String key : new HashSet<>(mapToEdit.keySet())) { if (mapToEdit.get(key) == null) { mapToEdit.remove(key); } if (mapToEdit.get(key) instanceof CharSequence) { CharSequence sequence = (CharSequence) mapToEdit.get(key); if (TextUtils.isEmpty(sequence)) { mapToEdit.remove(key); } } if (mapToEdit.get(key) instanceof Map) { Map<String, Object> stringObjectMap = (Map<String, Object>) mapToEdit.get(key); removeNullAndEmptyParams(stringObjectMap); } } }
StripeNetworkUtils { @SuppressWarnings("unchecked") public static void removeNullAndEmptyParams(@NonNull Map<String, Object> mapToEdit) { for (String key : new HashSet<>(mapToEdit.keySet())) { if (mapToEdit.get(key) == null) { mapToEdit.remove(key); } if (mapToEdit.get(key) instanceof CharSequence) { CharSequence sequence = (CharSequence) mapToEdit.get(key); if (TextUtils.isEmpty(sequence)) { mapToEdit.remove(key); } } if (mapToEdit.get(key) instanceof Map) { Map<String, Object> stringObjectMap = (Map<String, Object>) mapToEdit.get(key); removeNullAndEmptyParams(stringObjectMap); } } } }
StripeNetworkUtils { @SuppressWarnings("unchecked") public static void removeNullAndEmptyParams(@NonNull Map<String, Object> mapToEdit) { for (String key : new HashSet<>(mapToEdit.keySet())) { if (mapToEdit.get(key) == null) { mapToEdit.remove(key); } if (mapToEdit.get(key) instanceof CharSequence) { CharSequence sequence = (CharSequence) mapToEdit.get(key); if (TextUtils.isEmpty(sequence)) { mapToEdit.remove(key); } } if (mapToEdit.get(key) instanceof Map) { Map<String, Object> stringObjectMap = (Map<String, Object>) mapToEdit.get(key); removeNullAndEmptyParams(stringObjectMap); } } }  }
StripeNetworkUtils { @SuppressWarnings("unchecked") public static void removeNullAndEmptyParams(@NonNull Map<String, Object> mapToEdit) { for (String key : new HashSet<>(mapToEdit.keySet())) { if (mapToEdit.get(key) == null) { mapToEdit.remove(key); } if (mapToEdit.get(key) instanceof CharSequence) { CharSequence sequence = (CharSequence) mapToEdit.get(key); if (TextUtils.isEmpty(sequence)) { mapToEdit.remove(key); } } if (mapToEdit.get(key) instanceof Map) { Map<String, Object> stringObjectMap = (Map<String, Object>) mapToEdit.get(key); removeNullAndEmptyParams(stringObjectMap); } } }  @SuppressWarnings("unchecked") static void removeNullAndEmptyParams(@NonNull Map<String, Object> mapToEdit); }
StripeNetworkUtils { @SuppressWarnings("unchecked") public static void removeNullAndEmptyParams(@NonNull Map<String, Object> mapToEdit) { for (String key : new HashSet<>(mapToEdit.keySet())) { if (mapToEdit.get(key) == null) { mapToEdit.remove(key); } if (mapToEdit.get(key) instanceof CharSequence) { CharSequence sequence = (CharSequence) mapToEdit.get(key); if (TextUtils.isEmpty(sequence)) { mapToEdit.remove(key); } } if (mapToEdit.get(key) instanceof Map) { Map<String, Object> stringObjectMap = (Map<String, Object>) mapToEdit.get(key); removeNullAndEmptyParams(stringObjectMap); } } }  @SuppressWarnings("unchecked") static void removeNullAndEmptyParams(@NonNull Map<String, Object> mapToEdit);  }