config4k
config4k copied to clipboard
Feature request: converting hyphen-case to camelCase
According to docs:
Config keys are encouraged to be
hyphen-separated
rather thancamelCase
.
So, it would be nice to have this type of conversion as option.
Nice idea! I think the API should be like below.
object ConfigOption {
// Default value is camelCase, but it can be changed to hyphen-separated
var keyType: ConfigKeyType = ConfigKeyType.CAMEL_CASE
}
enum class ConfigKeyType {
CAMEL_CASE, HYPHEN_SEPARATED
}
How do you think, @ov7a?
In my experience, the common approach to this is to use annotations. (Take a look at jackson, for example). As user, the most convenient approach for me would be automatic conversion - unless the name is explicitly specified through annotation, first try the exact same name, then try camelCase variant. This would also allow to rename properties.
key = {
camelCaseProperty = value
hyphen-case-propery = value2
trashy_value = value3
}
data class MixedConfig(
val camelCaseProperty: String, //exact name
val hyphenCaseProperty: String, //converted automatically
@ConfigName("trashy_value") //explicit name
val annotatedProperty: String
)
For serializing data class to HOCON it would be logical to make an inverse conversion: transform all property names to hyphen-case, unless exact name is specified by annotation.
Thank you for your advice. This change is quite big and may break compatibility. So, it will be implemented in version 4.
https://github.com/config4k/config4k/pull/56 addresses the deserializing aspect of this issue. For serialization I would suggest looking at the ConfigSyntax
enum when implementing. According to HOCON standards, properties should be lowercase and hyphenated. It makes sense to serialize in the correct/strict format but have a more flexible deserializer
Unfortunately, we don't have a resources for implement this feature, but if someone want to do that, PRs are welcome anytime! 😄