https://kotlinlang.org logo
#jackson-kotlin
Title
# jackson-kotlin
f

Fredrik Larsen

05/19/2021, 11:08 AM
Hi, I have an issue with Jackson, Spring Boot and Kotlin 1.5 when using value classes. The converted json key includes the “special” class name suffix generated by the kotlin compiler for value classes. E.g. for
Copy code
data class Resource(
    val fooInterval: Milliseconds,
    val barInterval: Milliseconds?,
    …
)
@JvmInline
value class Milliseconds(val units: Int)
The generated json for
fooInterval
becomes
Copy code
"fooInterval-kqdxTu8": 900,
And for the nullable property it becomes
Copy code
"barInterval-OO-hnm0": {
        "units": 900
}
The suffix comes from the generated type (value class) but It looks like a bug that it is used as part of the parameter name. Any thoughts?
1
It seems to be work with
com.fasterxml.jackson.module:jackson-module-kotlin:2.12.3
Not quite fixed it seems. If it’s nullable it’s still wrapped. I’ll try to write custom serializers.
Fixed this by using
Copy code
@JvmInline
value class Milliseconds @JsonCreator constructor(@JsonValue val units: Int)
d

dinomite

05/19/2021, 2:21 PM
Ah, you added
@JsonCreator
and
@JsonValue
?
👍 1
7 Views