@Test public void shouldOverrideSimpleAndComplexElements() { Map<String, Object> original = new HashMap<>(); Map<String, Object> org = new HashMap<>(); org.put("a", "1"); Map<String, Object> org2 = new HashMap<>(); org2.put("c", "2"); org.put("e", org2); Map<String, Object> element = new HashMap<>(); element.put("a", "b"); Map<String, Object> element2 = new HashMap<>(); element2.put("c", "d"); element.put("e", element2); IOUtil.deepMerge(original, element); assertThat(original.containsKey("a"), is(true)); assertThat(original.containsKey("e"), is(true)); assertThat((String) original.get("a"), is("b")); Map<String, Object> innerElement = (Map<String, Object>) original.get("e"); assertThat(innerElement.containsKey("c"), is(true)); assertThat((String) innerElement.get("c"), is("d")); }
public static Map<String, Object> deepMerge(Map<String, Object> original, Map<String, Object> newMap) { for (String key : newMap.keySet()) { if (newMap.get(key) instanceof Map && original.get(key) instanceof Map) { Map<String, Object> originalChild = (Map<String, Object>) original.get(key); Map<String, Object> newChild = (Map) newMap.get(key); original.put(key, deepMerge(originalChild, newChild)); } else { original.put(key, newMap.get(key)); } } return original; }
IOUtil { public static Map<String, Object> deepMerge(Map<String, Object> original, Map<String, Object> newMap) { for (String key : newMap.keySet()) { if (newMap.get(key) instanceof Map && original.get(key) instanceof Map) { Map<String, Object> originalChild = (Map<String, Object>) original.get(key); Map<String, Object> newChild = (Map) newMap.get(key); original.put(key, deepMerge(originalChild, newChild)); } else { original.put(key, newMap.get(key)); } } return original; } }
IOUtil { public static Map<String, Object> deepMerge(Map<String, Object> original, Map<String, Object> newMap) { for (String key : newMap.keySet()) { if (newMap.get(key) instanceof Map && original.get(key) instanceof Map) { Map<String, Object> originalChild = (Map<String, Object>) original.get(key); Map<String, Object> newChild = (Map) newMap.get(key); original.put(key, deepMerge(originalChild, newChild)); } else { original.put(key, newMap.get(key)); } } return original; } private  IOUtil(); }
IOUtil { public static Map<String, Object> deepMerge(Map<String, Object> original, Map<String, Object> newMap) { for (String key : newMap.keySet()) { if (newMap.get(key) instanceof Map && original.get(key) instanceof Map) { Map<String, Object> originalChild = (Map<String, Object>) original.get(key); Map<String, Object> newChild = (Map) newMap.get(key); original.put(key, deepMerge(originalChild, newChild)); } else { original.put(key, newMap.get(key)); } } return original; } private  IOUtil(); static void tar(File file, File outputPath); static void untar(InputStream tarContent, File destination); static void unzip(InputStream in, File toDir); static String replacePlaceholders(String templateContent, Map<String, String> values); static String replacePlaceholdersWithWhiteSpace(final String templateContent,
        final Map<String, String> values); static String replacePlaceholdersWithWhiteSpace(final String templateContent); static String substringBetween(String str, String open, String close); static final String asString(final Map map); static final String asString(InputStream response); static String asStringPreservingNewLines(InputStream response); static String[] asArrayString(InputStream response); static Map<String, Object> deepMerge(Map<String, Object> original, Map<String, Object> newMap); static void copy(InputStream is, OutputStream os); static void close(Closeable closeable, boolean swallowIOException); }
IOUtil { public static Map<String, Object> deepMerge(Map<String, Object> original, Map<String, Object> newMap) { for (String key : newMap.keySet()) { if (newMap.get(key) instanceof Map && original.get(key) instanceof Map) { Map<String, Object> originalChild = (Map<String, Object>) original.get(key); Map<String, Object> newChild = (Map) newMap.get(key); original.put(key, deepMerge(originalChild, newChild)); } else { original.put(key, newMap.get(key)); } } return original; } private  IOUtil(); static void tar(File file, File outputPath); static void untar(InputStream tarContent, File destination); static void unzip(InputStream in, File toDir); static String replacePlaceholders(String templateContent, Map<String, String> values); static String replacePlaceholdersWithWhiteSpace(final String templateContent,
        final Map<String, String> values); static String replacePlaceholdersWithWhiteSpace(final String templateContent); static String substringBetween(String str, String open, String close); static final String asString(final Map map); static final String asString(InputStream response); static String asStringPreservingNewLines(InputStream response); static String[] asArrayString(InputStream response); static Map<String, Object> deepMerge(Map<String, Object> original, Map<String, Object> newMap); static void copy(InputStream is, OutputStream os); static void close(Closeable closeable, boolean swallowIOException);  }