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

Field names are being lowercased automatically when the first word of the camel-case is too short #475

Closed
hanzo2001 opened this issue Jul 7, 2021 · 2 comments

Comments

@hanzo2001
Copy link

I don't know if this is a feature or a bug but a quick search didn't return anything (or I didn't see it), or if this is something that only happens for Kotlin users.

I am using 2.12.4 but just in case, my POM has

    <dependencies>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.12.4</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>2.12.4</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.12.4</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.module</groupId>
            <artifactId>jackson-module-kotlin</artifactId>
            <version>2.12.4</version>
        </dependency>
    </dependencies>

The following may be run in a scratch.kt

import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper

val m = ObjectMapper()
val j = jacksonObjectMapper()

data class A(val someValue: String = "")
data class B(val sValue: String = "")
data class C(val rPoi: String = "")

m.writeValueAsString(A("cow").also(::println)).also(::println)
m.writeValueAsString(B("cow").also(::println)).also(::println)
m.writeValueAsString(C("cow").also(::println)).also(::println)

The output shows that the fields with short first word in the camel-case are being lowercased

A(someValue=cow)
{"someValue":"cow"}
B(sValue=cow)
{"svalue":"cow"}
C(rPoi=cow)
{"rpoi":"cow"}

I currently don't have an issue with this but it stumped me for a while because some of my Apache Camel routes started failing. I fixed it simply by using longer first names and it just works as expected.

Please let me know if I should try some other version. This is very easy to test as all I have to do is spin up a scratch (IntelliJ/IDEA) file and run it.

@cowtowncoder
Copy link
Member

Chances are this is due to Kotlin module's special handling of names, attempting to follow deviations Kotlin has from Java Beans specification (and sometimes from field-first aspect). So will transfer to Kotlin module; may be moved back if reproducible with plain Java test.

@k163377
Copy link
Contributor

k163377 commented Mar 3, 2023

The issue of property names in the serialization result differing from the definition in Kotlin will be addressed in #630.
This issue be closed as a duplicate.

@k163377 k163377 closed this as completed Mar 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants