1

So far, i found how to replace Javalin json mapper:

https://javalin.io/documentation#configuring-the-json-mapper

But i don't want to replace it, just want to add a few jackson modules, like this one:

https://www.ktorm.org/api-docs/org.ktorm.jackson/-ktorm-module/index.html

Without this, Javalin fails to serialize ktorm entities, sample code here

Sombriks
  • 3,370
  • 4
  • 34
  • 54

2 Answers2

6

Solved!

In JavalinConfig you can set an implementation of JsonMapper

The default implementation accepts an ObjectMapper as parameter, so i can do this:

// custom config to make ktor and jackson behave
val mapper = ObjectMapper()
mapper.registerModule(JavaTimeModule())
mapper.registerModule(KotlinModule.Builder().build())
mapper.registerModule(KtormModule())

// spin up app
val app = Javalin.create {
    it.jsonMapper(JavalinJackson(mapper))
}.start(3000)

And then Javalin and Ktorm works perfectly together.

UPDATE:

Now Javalin will detect KtormModule for you!

Sombriks
  • 3,370
  • 4
  • 34
  • 54
2

You can update the default Jackson mapper by doing:

val app = Javalin.create {
    config.jsonMapper(JavalinJackson().updateMapper { mapper ->
        mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL)
    })
}.start(3000)

See more at https://javalin.io/documentation#the-default-json-mapper-jackson

tipsy
  • 402
  • 4
  • 15