Skip to content

Commit

Permalink
fix: configure jackson properly for ktor http client json serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
osoykan committed Apr 22, 2024
1 parent 8c7d26a commit 9123a05
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ couchbase-client-metrics = { module = "com.couchbase.client:metrics-micrometer",
jackson-kotlin = { module = "com.fasterxml.jackson.module:jackson-module-kotlin", version.ref = "jackson" }
jackson-databind = { module = "com.fasterxml.jackson.core:jackson-databind", version.ref = "jackson" }
jackson-arrow = { module = "io.arrow-kt:arrow-integrations-jackson-module", version = "0.14.1" }
jackson-jsr310 = { module = "com.fasterxml.jackson.datatype:jackson-datatype-jsr310", version.ref = "jackson" }
slf4j-api = { module = "org.slf4j:slf4j-api", version.ref = "slf4j" }
slf4j-simple = { module = "org.slf4j:slf4j-simple", version.ref = "slf4j" }
ktor-server-host-common = { module = "io.ktor:ktor-server-host-common", version.ref = "ktor" }
Expand Down
1 change: 1 addition & 0 deletions lib/stove-testing-e2e-http/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ dependencies {
implementation(libs.ktor.client.content.negotiation)
implementation(libs.ktor.serialization.jackson.json)
testImplementation(projects.lib.stoveTestingE2eWiremock)
testImplementation(libs.jackson.jsr310)
}
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,7 @@ class HttpSystem(
}

install(ContentNegotiation) {
jackson {
setTypeFactory(objectMapper.typeFactory)
setConfig(objectMapper.deserializationConfig)
setConfig(objectMapper.serializationConfig)
setSerializerFactory(objectMapper.serializerFactory)
setNodeFactory(objectMapper.nodeFactory)
}
register(ContentType.Application.Json, JacksonConverter(objectMapper))
}

defaultRequest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package com.trendyol.stove.testing.e2e.http
import arrow.core.*
import com.github.tomakehurst.wiremock.client.WireMock.*
import com.github.tomakehurst.wiremock.matching.MultipartValuePattern
import com.trendyol.stove.testing.e2e.serialization.StoveObjectMapper
import com.trendyol.stove.testing.e2e.system.TestSystem
import com.trendyol.stove.testing.e2e.system.abstractions.ApplicationUnderTest
import com.trendyol.stove.testing.e2e.wiremock.*
import io.kotest.core.config.AbstractProjectConfig
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import java.time.Instant
import java.util.*

class NoApplication : ApplicationUnderTest<Unit> {
Expand All @@ -25,7 +27,13 @@ class TestConfig : AbstractProjectConfig() {
override suspend fun beforeProject(): Unit =
TestSystem("http://localhost:8086")
.with {
httpClient()
httpClient {
HttpClientSystemOptions(
objectMapper = StoveObjectMapper.byConfiguring {
findAndRegisterModules()
}
)
}

wiremock {
WireMockSystemOptions(8086)
Expand Down Expand Up @@ -235,8 +243,28 @@ class HttpSystemTests : FunSpec({
}
}
}

test("java time instant should work") {
val expectedGetDtoName = UUID.randomUUID().toString()
TestSystem.validate {
wiremock {
mockGet("/get", 200, responseBody = TestDtoWithInstant(expectedGetDtoName, Instant.now()).some())
}

http {
get<TestDtoWithInstant>("/get") { actual ->
actual.name shouldBe expectedGetDtoName
}
}
}
}
})

data class TestDto(
val name: String
)

data class TestDtoWithInstant(
val name: String,
val instant: Instant
)

0 comments on commit 9123a05

Please sign in to comment.