From 897788e3af59997a65b36b422e47e1370458322e Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Mon, 20 May 2024 13:31:31 -0600 Subject: [PATCH] Try builder first, then fallback to deprecated constructor --- .../common/converter/KotlinObjectMapperFactory.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/temporal-kotlin/src/main/kotlin/io/temporal/common/converter/KotlinObjectMapperFactory.kt b/temporal-kotlin/src/main/kotlin/io/temporal/common/converter/KotlinObjectMapperFactory.kt index 82a220b1a..399468591 100644 --- a/temporal-kotlin/src/main/kotlin/io/temporal/common/converter/KotlinObjectMapperFactory.kt +++ b/temporal-kotlin/src/main/kotlin/io/temporal/common/converter/KotlinObjectMapperFactory.kt @@ -29,9 +29,14 @@ class KotlinObjectMapperFactory { fun new(): ObjectMapper { val mapper = JacksonJsonPayloadConverter.newDefaultObjectMapper() - // use deprecated constructor instead of builder to maintain compatibility with old jackson versions - @Suppress("deprecation") - val km = KotlinModule() + val km = try { + KotlinModule.Builder() + .build() + } catch (e: NoClassDefFoundError) { + // use deprecated constructor as fallback + @Suppress("deprecation") + KotlinModule() + } mapper.registerModule(km) return mapper }