Open jotaporras opened 8 years ago
jotaporras changed the title from Your software sucks. to Convert Dash case to camel case 2 minutes ago
Sorry, my fault, I was fooling around. Hope you understand.
Have you tried using jackson's KebabCaseStrategy?
I'm not sure if this is what you want, but...
val HOCON_MAPPER = ObjectMapper(HoconFactory()).apply {
this.enable(MapperFeature.ALLOW_EXPLICIT_PROPERTY_RENAMING)
this.propertyNamingStrategy = object: PropertyNamingStrategy.PropertyNamingStrategyBase() {
override fun translate(p0: String): String {
val newField = StringBuilder()
for (ch in p0) {
if (ch.isUpperCase()) {
newField.append('-')
}
newField.append(ch.toLowerCase())
}
return newField.toString()
}
}
}
This allows you to use properties with camelCase while the source config (in HOCON) uses dashed-variables
class TestConfig(
@JsonProperty("camelCaseParam")
val camelCaseParam: String
)
val testConfig = Constants.HOCON_MAPPER.readValue<TestConfig>("camel-case-param = hello world")
println(testConfig.camelCaseParam)
displays hello world
When parsing HOCON, the mapper does not recognize dash case (e.g. 'sample-key: "a"') to convert it to camel case ('sampleKey')
PS: Sorry for the previous title. My co-worker was messing with my computer.