Home > Software engineering >  Javalin Migration
Javalin Migration

Time:12-30

I am new to Kotlin and Javalin. While migrating from Javalin 3 to 4, Javalinjackson.configure() function is deprecated. Below is the part of the code

import io.javalin.plugin.json.JavalinJackson
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper

val om = jacksonObjectMapper().apply { registerModule(JavaTimeModule()) }
JavalinJackson.configure(om)

I read in the documentation is that config.jsonMapper() is used now. Any pointers would be helpful.

CodePudding user response:

JavalinJackson is not a singleton any more. To "configure" it just pass your ObjectMapper as a constructor parameter:

val om = jacksonObjectMapper().apply { registerModule(JavaTimeModule()) }
val jacksonMapper = JavalinJackson(om)

and then pass resulting instance of JsonMapper into Javalin config:

val app = Javalin.create { config: JavalinConfig ->
    config.jsonMapper(jacksonMapper)
}.start()
  • Related