Closed
Description
I was surprised by the behavior of Jackson+Kotlin with respect to primitive parameters that have default values. It seems like those default values are ignored, and zero is used instead.
Here's an example:
class Main private constructor() {
compainion object {
@JvmStatic fun main(args: Array<String>) {
val mapper = ObjectMapper().registerModule(KotlinModule())
val string1 = "{\"i\":3}"
val string2 = "{}"
val value1 = mapper.readValue(string1, Foo::class.java)
val value2 = mapper.readValue(string2, Foo::class.java)
println("value1: $value1")
println("value2: $value2")
}
}
data class Foo
@JsonCreator constructor(@JsonProperty val i: Int = 5)
}
That prints:
value1: Foo(i=3)
value2: Foo(i=0)
But I wanted it to print:
value1: Foo(i=3)
value2: Foo(i=5)
Is that beyond the scope of this module? Is it impossible for some reason?
Metadata
Metadata
Assignees
Labels
No labels