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

@JsonProperty annotation ignored on camel case properties #603

Closed
fellmann opened this issue Nov 8, 2022 · 1 comment
Closed

@JsonProperty annotation ignored on camel case properties #603

fellmann opened this issue Nov 8, 2022 · 1 comment
Labels

Comments

@fellmann
Copy link

fellmann commented Nov 8, 2022

Describe the bug
@JsonProperty is ignored sometimes depending on the name of the property.

data class Works(
    @JsonProperty("AbCdE")
    val abc: String
)

data class Broken1(
    @JsonProperty("AbCdE")
    val ABC: String
)

data class Broken2(
    @JsonProperty("AbCdE")
    val aBC: String
)

fun main() {
    val om = jacksonObjectMapper()

    println(om.writeValueAsString(Works("test")))
    // {"AbCdE":"test"}

    println(om.writeValueAsString(Broken1("test")))
    // {"abc":"test"}

    println(om.writeValueAsString(Broken2("test")))
    // {"abc":"test"}
}

To Reproduce
See code above.

Expected behavior
All examples serialize to {"AbCdE":"test"}.

Versions
Kotlin: 1.7.20
Jackson-module-kotlin: 2.13.4
Jackson-databind: 2.13.4.2

@fellmann fellmann added the bug label Nov 8, 2022
@k163377
Copy link
Contributor

k163377 commented Mar 3, 2023

@fellmann
First, annotating the getter eliminates this problem.

import com.fasterxml.jackson.annotation.JsonProperty

data class Works(
    @get:JsonProperty("AbCdE")
    val abc: String
)

data class Broken1(
    @get:JsonProperty("AbCdE")
    val ABC: String
)

data class Broken2(
    @get:JsonProperty("AbCdE")
    val aBC: String
)

The root cause is that the name of the getter in the JVM takes precedence, resulting in a discrepancy between the property name and the parameter name on Jackson and a failure to tie the annotation together.
This problem can be resolved by implementing #630.

This issue will be closed as a duplicate of #630.

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