night-config
night-config copied to clipboard
Support for arbitrary HashMap de/serialization
Sometimes which exact keys will exist in a config file are up to the user. I am not sure whether I am doing something wrong, or whether this is not implemented, but it doesn't seem possible to do in night-config.
public class MyConfig
@Path("commands")
@PreserveNotNull
public Map<String, CustomCommandConfigEntry> commands = new HashMap<>();
}
This will throw the following exception:
Caused by: com.electronwill.nightconfig.core.io.WritingException: Unsupported value type: class java.util.HashMap
Subconfigs are supported, they must be Config
not HashMap
:
public class MyConfig {
public Config commands;
}
If you or someone else wonder why, let me explain :)
A configuration is a hierarchical data structure. You can access its different levels from anywhere with config.get("parent.child.grandchild")
. To walk through the hierarchy, it's simpler and more efficient to enforce a single type of parent node. On top of that, it allows to store additional information such as comments.