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

Maksim Vlasov

06/04/2019, 10:28 AM
I want to use Kotlin data class in java with jackson serializer. If I want to use koltin data class from Java then I must set default parameters to create a default constructor for jackson serializer. Is there any other way?
e

Evan R.

06/04/2019, 12:44 PM
Try using the Jackson Kotlin Module. It adds support for this. https://github.com/FasterXML/jackson-module-kotlin
m

Maksim Vlasov

06/04/2019, 1:56 PM
@Evan R. thank you for response! So I have to add it to the Java project, am I right?
Does it require any setup in such case? or just add it instead of jackson and that is it?
e

Evan R.

06/04/2019, 4:09 PM
It’s a module that plugs into jackson. Instructions are on the readme of the repo I linked you to, but TL;DR is that you apply the Kotlin Module to the Object Mapper wherever you have it defined, or in Kotlin you can just call the extension function
.registerKotlinModule()
on the ObjectMapper
m

Maksim Vlasov

06/05/2019, 10:05 AM
@Evan R. thank you!
👍 1
149 Views