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

camelCased property not properly serialized #570

Closed
nilswieber opened this issue Jun 2, 2022 · 3 comments
Closed

camelCased property not properly serialized #570

nilswieber opened this issue Jun 2, 2022 · 3 comments
Labels

Comments

@nilswieber
Copy link

Describe the bug
An object with a camelCased property, which starts with a single lowercase character isn't properly serialized.

To Reproduce

fun main(args: Array<String>) {
    val mapper = jacksonObjectMapper()

    val serialized = mapper.writeValueAsString(Test())
    println(serialized)
    val deserialized = mapper.readValue<Test>(serialized)
}

class Test {
    val cCase = 1
}

Expected behavior
The property should be correctly serialized as cCase but it is serialized as ccase.

So the provided code snippet prints the string {"ccase":1} instead of {"cCase":1}

Because of this behavior the deserialization fails with the following error:

Exception in thread "main" com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "ccase" (class de.nilswieber.Test), not marked as ignorable (0 known properties: ])
 at [Source: (String)"{"ccase":1}"; line: 1, column: 11] (through reference chain: de.nilswieber.Test["ccase"])
	at com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:61)
	at com.fasterxml.jackson.databind.DeserializationContext.handleUnknownProperty(DeserializationContext.java:1127)
	at com.fasterxml.jackson.databind.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:2023)
	at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownProperty(BeanDeserializerBase.java:1700)
	at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownVanilla(BeanDeserializerBase.java:1678)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:319)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:176)
	at com.fasterxml.jackson.databind.deser.DefaultDeserializationContext.readRootValue(DefaultDeserializationContext.java:323)
	at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4674)
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3629)
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3612)
	at de.nilswieber.MainKt.main(Main.kt)

Versions
Kotlin:
Jackson-module-kotlin: 2.13.3
Jackson-databind: 2.13.3

Additional context
This issue is likely related to #172 and #173

@nilswieber nilswieber added the bug label Jun 2, 2022
@nilswieber
Copy link
Author

One workaround would be to annotate the property with @get:JvmName("getcCase") like so:

class Test {
    @get:JvmName("getcCase")
    val cCase = 1
}

This causes Jackson to recognize the field in the correct way.

@cowtowncoder
Copy link
Member

@nilswieber Or @JsonProperty("cCase")

@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
Projects
None yet
Development

No branches or pull requests

3 participants