Skip to content

Incorrect handling of properties starting with a single lowercase letter #921

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

Closed
3 of 4 tasks
naftalmm opened this issue Mar 18, 2025 · 1 comment
Closed
3 of 4 tasks
Labels

Comments

@naftalmm
Copy link

Search before asking

  • I searched in the issues and found nothing similar.
  • I have confirmed that the same problem is not reproduced if I exclude the KotlinModule.
  • I searched in the issues of databind and other modules used and found nothing similar.
  • I have confirmed that the problem does not reproduce in Java and only occurs when using Kotlin and KotlinModule.

Describe the bug

Data classes with properties starting with a single lowercase letter are handled incorrectly, changing to lowercase whole group of sequential uppercase letters following it in property name:

aBcd -> abcd
aBBBBBBBBcd -> abbbbbbbbcd
aBaB -> abaB

This results in inaccurate JSON & inability to deserialize it back with the same data class.

To Reproduce

import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue

data class BugTest(/*@get:JvmName("getaBcd") or @get:JsonProperty("aBcd") fixes the issue*/val aBcd: Int)

fun main() {
    val mapper = jacksonObjectMapper()
    val json = mapper.writeValueAsString(BugTest(1))
    println(json) // expected: {"aBcd":1}, actual: {"abcd":1}
    mapper.readValue<BugTest>(json) // com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "abcd" (class BugTest), not marked as ignorable (one known property: "aBcd"])
}

Expected behavior

Prints {"aBcd":1}, exits successfully.

Versions

Kotlin: Any
Jackson-module-kotlin: 2.18.2
Jackson-databind: 2.18.2

Additional context

There is a similar bug for databind, but I believe Kotlin module could handle it in its own way, since the root cause of databind's bug is a method it restores field name from getter name, while Kotlin module can directly access data class properties names and not rely on Kotlin's compiler-generated getters (which is getABcd in this case by the way).

@naftalmm naftalmm added the bug label Mar 18, 2025
@k163377
Copy link
Contributor

k163377 commented Mar 19, 2025

Please use KotlinFeature.KotrinPropertyNameAsImplicitName.
This issue is closed as a duplicate of #630.

@k163377 k163377 closed this as completed Mar 19, 2025
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