Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to disable the feature who rename a primitive boolean "isXXX" to "XXX" #781

Open
SannaK opened this issue Apr 2, 2024 · 1 comment
Labels

Comments

@SannaK
Copy link

SannaK commented Apr 2, 2024

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.

@SannaK SannaK added the question label Apr 2, 2024
@SannaK SannaK changed the title How to disable the feature who renamming isXXX boolean to XXX How to disable the feature who renaming a primitive boolean "isXXX" to "XXX" Apr 2, 2024
@SannaK SannaK changed the title How to disable the feature who renaming a primitive boolean "isXXX" to "XXX" How to disable the feature who rename a primitive boolean "isXXX" to "XXX" Apr 2, 2024
@k163377
Copy link
Contributor

k163377 commented Apr 8, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants