Java Map Merge deepMerge(Map original, Map newMap)

Here you can find the source of deepMerge(Map original, Map newMap)

Description

deep Merge

License

Apache License

Declaration

public static Map<String, Object> deepMerge(Map<String, Object> original, Map<String, Object> newMap) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Map;

public class Main {
    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));
            }/*from w  w  w . j  a v  a 2s.  c o m*/
        }
        return original;
    }
}

Related

  1. deepMerge(Map dst, Map src)
  2. deepMerge(Map m1, Map m2)
  3. merge(final Map lhs, final Map rhs)
  4. merge(final Map map1, final Map map2)
  5. merge(final Map... maps)
  6. merge(final Map> targetContext, final Map> newContext)