Of course I want to follow the best practices. That’s how I do configs. @ConfigSerializable
for the classes and optionally @Setting
for comments.
The keys in the config are the same like in code. Is there an automatic way to convert the camelCase to hyphen-separated-keys in the actual config?
The value()
field in @Setting
represents the config pathname.
Yeah, I am looking for an automatic way. Like a formatter that turns the key name to hyphen separated.
You could do this by creating a custom ObjectMapper
. I did something similar in Nucleus, but instead of transforming the name of the setting, I was trying to transform the comment to make it fit with my localisation system a bit better.
I did what I needed to do like this - you’d put your own logic there to split the camel case to hyphen separated keys.
(this is just the standard ObjectMapper method from Configurate with lines 35-38 added.)
I then created a ObjectMapperFactory
to go with it (this was a lot of copy and paste from the standard factory, there might be a better way to do it):
then just had to register the factory when building the configuration loader.