config
config copied to clipboard
parseMap can't handle keys with special characters
In the following code, I never reach the final line:
// quoted key containing an '@' is alright:
Config config = ConfigFactory.parseString("\"hah@a\": hehe");
System.out.println("config.root().render(): " + config.root().render());
// Config's rendering function quotes keys and values OK:
Config reConfig = ConfigFactory.parseString(config.root().render());
System.out.println("reConfig.root().render(): " + reConfig.root().render());
// Converting to a map is OK:
Map<String, ?> map = config.root().unwrapped();
System.out.println("map: " + map);
// But recapturing as a config from that very same map isn't:
Config reReConfig = ConfigFactory.parseMap(map);
System.out.println("reReConfig.root().render():" + reReConfig.root().render());
The parseMap method throws a ConfigException$BadPath. Is this really meant to be so?
By calling root() you get the types mixed up; you’re creating a map that’s a json-like tree data structure with syntaxless string keys, and passing it to parseMap which expects a 1-level flat data structure with paths as keys.
You mean by calling unwrapped()? It does indeed not crash when I drop the call to unwrapped(). Thanks.