Search code examples
javahocon

How to read HOCON config to load values into Map?


I have a config as mentioned here

map-config{  
      key1 : [ list1, list2, list3 ],
      key2 : [ list4, list5 ],
      key3 : [ list6 ]    
   }

Once after loading I except it have a Map with keyset as key1, key2 and key3 whose corresponding values will be a list with list1, list2, list3, list4, list5 and list6.


Solution

  • I haven't find direct method call but the following piece of code can help me store configuration values in Map<String, List<String>>

    private static void method(Config config) {
        for( Entry<String, ConfigValue> element : config.entrySet()){
            String key = element.getKey();
            map.put(key, config.getStringList(key));
        }
    }