UaaMapUtils { public static <K extends Comparable<? super K>, V> Map<K, V> sortByKeys(Map<K,V> map) { List<Entry<K, V>> sortedEntries = map .entrySet() .stream() .sorted(comparingByKey()) .collect(Collectors.toList()); LinkedHashMap<K, V> result = new LinkedHashMap<>(); for (Map.Entry<K, V> entry : sortedEntries) { Object value = entry.getValue(); if (value instanceof Map) { value = sortByKeys((Map) value); } result.put(entry.getKey(), (V)value); } return result; }  static Map<String, Object> flatten(Map<String, Object> map); static Map<String, Object> getPropertiesStartingWith(ConfigurableEnvironment aEnv,
                                                                String aKeyPrefix); static Map<String, Object> getAllProperties(ConfigurableEnvironment aEnv); static Map<String, Object> getAllProperties(PropertySource<?> aPropSource); @SafeVarargs static Map<K, V> map(E... entries); static Map.Entry<K, V> entry(K key, V value); static Map<K, V> sortByKeys(Map<K,V> map); static String prettyPrintYaml(Map<K,V> map); static Map<String, ?> redactValues(Map<String, ?> map);  }
@Test public void sort_nested_map() { List<String> expectedOrder = Arrays.asList( "secondA", "thirdA", "keyA", "thirdB", "keyB", "secondB", "thirdB", "keyB", "thirdC", "emptyMap", "emptyString", "keyC", "nullValue" ); assertNotEquals(expectedOrder, visit_all_keys(top)); assertEquals(expectedOrder, visit_all_keys(sortByKeys(top))); }