From 465105b5c5fa5ff58c1235d127f125936ab787aa Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Mon, 20 May 2024 13:31:31 -0600 Subject: [PATCH 1/4] 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 82a220b1a9..3994685913 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 } From 67cc4b2c70c2a031ea31f5635a255de2ce097544 Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Wed, 22 May 2024 18:09:58 -0600 Subject: [PATCH 2/4] Add jackson 2.9.0 and 2.14.2 tests --- temporal-kotlin/build.gradle | 25 +++++++++++++++++++ .../KotlinObjectMapperFactoryTest.kt | 13 ++++++++++ .../KotlinObjectMapperFactoryTest.kt | 13 ++++++++++ 3 files changed, 51 insertions(+) create mode 100644 temporal-kotlin/src/jackson2.14.2Test/kotlin/io/temporal/common/converter/KotlinObjectMapperFactoryTest.kt create mode 100644 temporal-kotlin/src/jackson2.9.0Test/kotlin/io/temporal/common/converter/KotlinObjectMapperFactoryTest.kt diff --git a/temporal-kotlin/build.gradle b/temporal-kotlin/build.gradle index d542da8d1e..71ca39ad6e 100644 --- a/temporal-kotlin/build.gradle +++ b/temporal-kotlin/build.gradle @@ -1,4 +1,5 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile +import org.gradle.api.plugins.jvm.JvmTestSuite plugins { id 'org.jlleitschuh.gradle.ktlint' version '11.3.1' @@ -43,3 +44,27 @@ task registerNamespace(type: JavaExec) { test.dependsOn 'registerNamespace' +def jacksonVersions = ['2.9.0', "$jacksonVersion".toString()] + +testing { + suites { + jacksonVersions.forEach { jacksonVersion -> + "jackson${jacksonVersion}Test"(JvmTestSuite) { + useJUnit(junitVersion) + dependencies { + implementation project() + implementation "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jacksonVersion!!" + implementation "com.fasterxml.jackson.datatype:jackson-datatype-jdk8:$jacksonVersion!!" + implementation("com.fasterxml.jackson.module:jackson-module-kotlin:$jacksonVersion!!") { + exclude group: 'org.jetbrains.kotlin', module: 'kotlin-reflect' + } + + implementation project(':temporal-testing') + implementation "junit:junit:${junitVersion}" + } + } + } + } +} + +test.dependsOn("jackson2.9.0Test", "jackson2.14.2Test") diff --git a/temporal-kotlin/src/jackson2.14.2Test/kotlin/io/temporal/common/converter/KotlinObjectMapperFactoryTest.kt b/temporal-kotlin/src/jackson2.14.2Test/kotlin/io/temporal/common/converter/KotlinObjectMapperFactoryTest.kt new file mode 100644 index 0000000000..717df8591d --- /dev/null +++ b/temporal-kotlin/src/jackson2.14.2Test/kotlin/io/temporal/common/converter/KotlinObjectMapperFactoryTest.kt @@ -0,0 +1,13 @@ +package io.temporal.common.converter + +import com.fasterxml.jackson.module.kotlin.PackageVersion +import org.junit.Assert.assertEquals +import org.junit.Test + +class KotlinObjectMapperFactoryTest { + @Test + fun `test jackson 2 14 2`() { + assertEquals(PackageVersion.VERSION.toString(), "2.14.2") + KotlinObjectMapperFactory.new() + } +} diff --git a/temporal-kotlin/src/jackson2.9.0Test/kotlin/io/temporal/common/converter/KotlinObjectMapperFactoryTest.kt b/temporal-kotlin/src/jackson2.9.0Test/kotlin/io/temporal/common/converter/KotlinObjectMapperFactoryTest.kt new file mode 100644 index 0000000000..2ca61c6947 --- /dev/null +++ b/temporal-kotlin/src/jackson2.9.0Test/kotlin/io/temporal/common/converter/KotlinObjectMapperFactoryTest.kt @@ -0,0 +1,13 @@ +package io.temporal.common.converter + +import com.fasterxml.jackson.module.kotlin.PackageVersion +import org.junit.Assert.assertEquals +import org.junit.Test + +class KotlinObjectMapperFactoryTest { + @Test + fun `test jackson 2 9 0`() { + assertEquals(PackageVersion.VERSION.toString(), "2.9.0") + KotlinObjectMapperFactory.new() + } +} From addc854fe59d1432f1990b4b030f0868c3e9a6b8 Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Wed, 22 May 2024 18:21:09 -0600 Subject: [PATCH 3/4] Use registerKotlinModule function to retain backwards compatibility --- .../common/converter/KotlinObjectMapperFactory.kt | 13 ++----------- 1 file changed, 2 insertions(+), 11 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 3994685913..42503f58a8 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 @@ -21,7 +21,7 @@ package io.temporal.common.converter import com.fasterxml.jackson.databind.ObjectMapper -import com.fasterxml.jackson.module.kotlin.KotlinModule +import com.fasterxml.jackson.module.kotlin.registerKotlinModule class KotlinObjectMapperFactory { companion object { @@ -29,16 +29,7 @@ class KotlinObjectMapperFactory { fun new(): ObjectMapper { val mapper = JacksonJsonPayloadConverter.newDefaultObjectMapper() - val km = try { - KotlinModule.Builder() - .build() - } catch (e: NoClassDefFoundError) { - // use deprecated constructor as fallback - @Suppress("deprecation") - KotlinModule() - } - mapper.registerModule(km) - return mapper + return mapper.registerKotlinModule() } } } From f1ca36adc30d3234c5d36b9974a39ccdf78216bb Mon Sep 17 00:00:00 2001 From: Clayton Walker Date: Wed, 22 May 2024 21:39:26 -0600 Subject: [PATCH 4/4] Fix license --- .../KotlinObjectMapperFactoryTest.kt | 20 +++++++++++++++++++ .../KotlinObjectMapperFactoryTest.kt | 20 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/temporal-kotlin/src/jackson2.14.2Test/kotlin/io/temporal/common/converter/KotlinObjectMapperFactoryTest.kt b/temporal-kotlin/src/jackson2.14.2Test/kotlin/io/temporal/common/converter/KotlinObjectMapperFactoryTest.kt index 717df8591d..16da2f488c 100644 --- a/temporal-kotlin/src/jackson2.14.2Test/kotlin/io/temporal/common/converter/KotlinObjectMapperFactoryTest.kt +++ b/temporal-kotlin/src/jackson2.14.2Test/kotlin/io/temporal/common/converter/KotlinObjectMapperFactoryTest.kt @@ -1,3 +1,23 @@ +/* + * Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved. + * + * Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this material except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package io.temporal.common.converter import com.fasterxml.jackson.module.kotlin.PackageVersion diff --git a/temporal-kotlin/src/jackson2.9.0Test/kotlin/io/temporal/common/converter/KotlinObjectMapperFactoryTest.kt b/temporal-kotlin/src/jackson2.9.0Test/kotlin/io/temporal/common/converter/KotlinObjectMapperFactoryTest.kt index 2ca61c6947..f70d765dd8 100644 --- a/temporal-kotlin/src/jackson2.9.0Test/kotlin/io/temporal/common/converter/KotlinObjectMapperFactoryTest.kt +++ b/temporal-kotlin/src/jackson2.9.0Test/kotlin/io/temporal/common/converter/KotlinObjectMapperFactoryTest.kt @@ -1,3 +1,23 @@ +/* + * Copyright (C) 2022 Temporal Technologies, Inc. All Rights Reserved. + * + * Copyright (C) 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this material except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package io.temporal.common.converter import com.fasterxml.jackson.module.kotlin.PackageVersion