public static <K, V> Map<K, V> deepMerge(
            Map<K, V> baseMap,
            Map<? extends K, ? extends V> mapToMerge,
            boolean appendCollectionElements) {
        for (Map.Entry<? extends K, ? extends V> entry : mapToMerge.entrySet()) {
            K key = entry.getKey();
            V existingValue = baseMap.get(key);
            V valueToMerge = entry.getValue();
            // We don't need to handle the case of arrays
            // just because we don't use arrays.
            if (appendCollectionElements
                    && existingValue instanceof Collection existingValues
                    && valueToMerge instanceof Collection valuesToMerge) {
                if (!existingValues.containsAll(valuesToMerge)) {
                    existingValues.addAll(valuesToMerge);
                }
            } else if (existingValue instanceof Map existingValueMap
                    && valueToMerge instanceof Map valueToMergeMap) {
                deepMerge(existingValueMap, valueToMergeMap, appendCollectionElements);
            } else if (existingValue == null || !existingValue.equals(valueToMerge)) {
                baseMap.put(key, valueToMerge);
            }
        }
        return baseMap;
    }
Note that the method only checks the immutable classes used by Turms.
turms-server-common/src/main/java/im/turms/server/common/infra/collection/CollectionUtil.java