Hi, I have an issue with Jackson, Spring Boot and ...
# jackson-kotlin
f
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
Ah, you added
@JsonCreator
and
@JsonValue
?
👍 1