jackson-module-kotlin
jackson-module-kotlin copied to clipboard
How to disable the feature who rename a primitive boolean "isXXX" to "XXX"
Your question
Hello,
I know is a feature but it's annoying in my case : how to avoid the serializer to renamme my property "isAvailable" to "available". I want to keep the exact name. The expected resulst should be "is_available" with my settings.
internal fun getPrettyMapper(): ObjectWriter = ObjectMapper()
.setMixInResolver(object : ClassIntrospector.MixInResolver {
override fun findMixInClassFor(cls: Class<*>?): Class<*>? {
return when (cls) {
AppError::class.java -> AppErrorJson::class.java
Resource::class.java -> ResourceJson::class.java
else -> null
}
}
override fun copy() = this
})
.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE)
.writerWithDefaultPrettyPrinter()
Thanks for your help.
The following answer relates to the latest version (it would be helpful if you could attach the version information to your explanation).
As I recall, this problem is caused by KotlinModule performing internal processing in a function called findImplicitPropertyName.
https://www.javadoc.io/doc/com.fasterxml.jackson.core/jackson-databind/latest/com/fasterxml/jackson/databind/AnnotationIntrospector.html#findImplicitPropertyName-com.fasterxml.jackson.databind.introspect.AnnotatedMember-
In other words, the KotlinModule has to wait for this problem to be fixed on the databind side.
For individual use cases, a custom AnnotationIntrospector can also be used to fix names across the board (possible side effects, but not likely to be a problem for limited use cases).
https://www.javadoc.io/doc/com.fasterxml.jackson.core/jackson-databind/latest/com/fasterxml/jackson/databind/AnnotationIntrospector.html
I am very sorry, but I am very busy right now and cannot investigate this in detail.
The problem is assumed to have been resolved and closed.