private void buildFlattenedMap(Map<String, Object> result, Map<String, Object> source,
      String path) {
    for (Map.Entry<String, Object> entry : source.entrySet()) {
      String key = entry.getKey();
      if (hasText(path)) {
        if (key.startsWith("[")) {
          key = path + key;
        } else {
          key = path + "." + key;
        }
      }
      Object value = entry.getValue();
      if (value instanceof String) {
        result.put(key, value);
      } else if (value instanceof Map) {
        // Need a compound key
        @SuppressWarnings("unchecked")
        Map<String, Object> map = (Map<String, Object>) value;
        buildFlattenedMap(result, map, key);
      } else if (value instanceof Collection) {
        // Need a compound key
        @SuppressWarnings("unchecked")
        Collection<Object> collection = (Collection<Object>) value;
        int count = 0;
        for (Object object : collection) {
          buildFlattenedMap(result, Collections.singletonMap("[" + (count++) + "]", object), key);
        }
      } else {
        result.put(key, value != null ? value : "");
      }
    }
  }
Return a flattened version of the given map, recursively following any nested Map or Collection
values. Entries from the resulting map retain the same order as the source.
src/main/java/com/eudemon/ratelimiter/env/resolver/YamlPropertySourceResolver.java