Skip to content

Failed deserialization of fields where only the first character is lowercase #503

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
junkdog opened this issue Sep 24, 2021 · 2 comments
Closed
Labels

Comments

@junkdog
Copy link

junkdog commented Sep 24, 2021

Describe the bug

Serialization of fields starting with a single lowercase character followed by an uppercase character are serialized as all lowercase. This causes deserialization to fail as jackson tries to deserialize according to the "original"/camelCased field name. E.g. pId is serialized as pid but expects pId during deserialization.

To Reproduce

data class FooBar(
    val id: String,
    val nId: String, // expected name: nId, actual: nid
)

fun main() {
    val fooBar = FooBar("bar", "foo")
    val json = jacksonObjectMapper().writeValueAsString(fooBar)
    assert(fooBar == jacksonObjectMapper().readValue<FooBar>(json))
}

Expected behavior

Serialized fields names should match the original field name.

Versions
Kotlin: 1.5.30
Jackson-module-kotlin: 2.12.5
Jackson-databind: 2.12.5

Additional context
Add any other context about the problem here.

@junkdog junkdog added the bug label Sep 24, 2021
@junkdog junkdog changed the title Failed deerialization of fields where only the first character is lowercase Failed deserialization of fields where only the first character is lowercase Sep 24, 2021
@AndChelp
Copy link

AndChelp commented Sep 28, 2021

+1
Hint where to find the bug:
com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector#collectAll
com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector#_addMethods
com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector#_addGetterMethod
com.fasterxml.jackson.databind.ser.BeanSerializerFactory#removeIgnorableTypes

This is because pId has a getPId and setPId format accessor. Jackson extracts the PId from here and makes the letters lowercase until it encounters a lowercase letter (PId -> pid).
Quckfix for it - add @JsonProperty("pId") on accessor for Java. Or @get:JsonProperty("pId") / @param:JsonProperty("pId") for kotlin

@k163377
Copy link
Contributor

k163377 commented Mar 17, 2023

This issue will be fixed by #630 and therefore closed as a duplicate.

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

3 participants