Skip to content

Commit 9123a05

Browse files
committed
fix: configure jackson properly for ktor http client json serialization
1 parent 8c7d26a commit 9123a05

File tree

4 files changed

+32
-8
lines changed

4 files changed

+32
-8
lines changed

gradle/libs.versions.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ couchbase-client-metrics = { module = "com.couchbase.client:metrics-micrometer",
5252
jackson-kotlin = { module = "com.fasterxml.jackson.module:jackson-module-kotlin", version.ref = "jackson" }
5353
jackson-databind = { module = "com.fasterxml.jackson.core:jackson-databind", version.ref = "jackson" }
5454
jackson-arrow = { module = "io.arrow-kt:arrow-integrations-jackson-module", version = "0.14.1" }
55+
jackson-jsr310 = { module = "com.fasterxml.jackson.datatype:jackson-datatype-jsr310", version.ref = "jackson" }
5556
slf4j-api = { module = "org.slf4j:slf4j-api", version.ref = "slf4j" }
5657
slf4j-simple = { module = "org.slf4j:slf4j-simple", version.ref = "slf4j" }
5758
ktor-server-host-common = { module = "io.ktor:ktor-server-host-common", version.ref = "ktor" }

lib/stove-testing-e2e-http/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ dependencies {
1010
implementation(libs.ktor.client.content.negotiation)
1111
implementation(libs.ktor.serialization.jackson.json)
1212
testImplementation(projects.lib.stoveTestingE2eWiremock)
13+
testImplementation(libs.jackson.jsr310)
1314
}

lib/stove-testing-e2e-http/src/main/kotlin/com/trendyol/stove/testing/e2e/http/HttpSystem.kt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -268,13 +268,7 @@ class HttpSystem(
268268
}
269269

270270
install(ContentNegotiation) {
271-
jackson {
272-
setTypeFactory(objectMapper.typeFactory)
273-
setConfig(objectMapper.deserializationConfig)
274-
setConfig(objectMapper.serializationConfig)
275-
setSerializerFactory(objectMapper.serializerFactory)
276-
setNodeFactory(objectMapper.nodeFactory)
277-
}
271+
register(ContentType.Application.Json, JacksonConverter(objectMapper))
278272
}
279273

280274
defaultRequest {

lib/stove-testing-e2e-http/src/test/kotlin/com/trendyol/stove/testing/e2e/http/HttpSystemTests.kt

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ package com.trendyol.stove.testing.e2e.http
33
import arrow.core.*
44
import com.github.tomakehurst.wiremock.client.WireMock.*
55
import com.github.tomakehurst.wiremock.matching.MultipartValuePattern
6+
import com.trendyol.stove.testing.e2e.serialization.StoveObjectMapper
67
import com.trendyol.stove.testing.e2e.system.TestSystem
78
import com.trendyol.stove.testing.e2e.system.abstractions.ApplicationUnderTest
89
import com.trendyol.stove.testing.e2e.wiremock.*
910
import io.kotest.core.config.AbstractProjectConfig
1011
import io.kotest.core.spec.style.FunSpec
1112
import io.kotest.matchers.shouldBe
13+
import java.time.Instant
1214
import java.util.*
1315

1416
class NoApplication : ApplicationUnderTest<Unit> {
@@ -25,7 +27,13 @@ class TestConfig : AbstractProjectConfig() {
2527
override suspend fun beforeProject(): Unit =
2628
TestSystem("http://localhost:8086")
2729
.with {
28-
httpClient()
30+
httpClient {
31+
HttpClientSystemOptions(
32+
objectMapper = StoveObjectMapper.byConfiguring {
33+
findAndRegisterModules()
34+
}
35+
)
36+
}
2937

3038
wiremock {
3139
WireMockSystemOptions(8086)
@@ -235,8 +243,28 @@ class HttpSystemTests : FunSpec({
235243
}
236244
}
237245
}
246+
247+
test("java time instant should work") {
248+
val expectedGetDtoName = UUID.randomUUID().toString()
249+
TestSystem.validate {
250+
wiremock {
251+
mockGet("/get", 200, responseBody = TestDtoWithInstant(expectedGetDtoName, Instant.now()).some())
252+
}
253+
254+
http {
255+
get<TestDtoWithInstant>("/get") { actual ->
256+
actual.name shouldBe expectedGetDtoName
257+
}
258+
}
259+
}
260+
}
238261
})
239262

240263
data class TestDto(
241264
val name: String
242265
)
266+
267+
data class TestDtoWithInstant(
268+
val name: String,
269+
val instant: Instant
270+
)

0 commit comments

Comments
 (0)