Closed alturkovic closed 3 weeks ago
Any updates?
@alturkovic Sorry for the delay.
I just checked on branch 2.18 and it succeeded in all cases.
package com.fasterxml.jackson.module.kotlin
import kotlin.random.Random
fun main() {
val mapper = jacksonObjectMapper()
val testing = Testing()
val json = mapper.writeValueAsString(testing)
println(json) // {} works correctly
println(mapper.readValue<Testing>(json)) // Testing(random=kotlin.random.Random$Default@57459491)
}
data class Testing(
private val random: Random = Random
)
package com.fasterxml.jackson.module.kotlin
import com.fasterxml.jackson.annotation.JacksonInject
import com.fasterxml.jackson.databind.InjectableValues
import com.fasterxml.jackson.databind.ObjectMapper
fun main() {
val mapper = ObjectMapper()
.registerModule(kotlinModule {
enable(KotlinFeature.NullIsSameAsDefault)
})
.setInjectableValues(InjectableValues.Std().addValue(String::class.java, "Example"))
val testing = mapper.readValue<Testing>("{}") // Example
println(testing.id)
}
data class Testing(
@JacksonInject val id: String
)
If this has been fixed, could you please close it?
I just tested it with 2.18.0-rc1 and it worked. Thank you! Closing the issue.
Search before asking
Describe the bug
The example below will not deserialize a single-field data class with a default value:
But if I add another field to class, it works as expected:
I have also noticed that it works with a single primitive field:
Another example is with
@JacksonInject
:But adding another field do the data class fixes the problem:
To Reproduce
No response
Expected behavior
No response
Versions
Kotlin: 1.9.20 Jackson-module-kotlin: 2.16.0 Jackson-databind: 2.16.0
Additional context
No response