diff --git a/.github/workflows/boot3-compat-demo.yml b/.github/workflows/boot3-compat-demo.yml new file mode 100644 index 000000000..eb0e4899e --- /dev/null +++ b/.github/workflows/boot3-compat-demo.yml @@ -0,0 +1,100 @@ +# Demo for PR #189 (Jackson 3). In a Spring Boot 3 app, Boot's BOM picks the +# jackson-annotations and Kotlin versions, while the SDK picks the Jackson 3 engine. +# When the engine needs newer ones than Boot supplies, the app fails with NoClassDefFoundError. +name: Boot 3 compatibility demo + +on: + push: + branches: + - demo/boot3-jackson-annotations + +jobs: + boot3-compat: + name: Boot ${{ matrix.boot }} + Jackson ${{ matrix.jackson || '3.1.7 (PR default)' }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - boot: '3.5.12' + jackson: '' + expect: fail + why: 'annotations 2.19 < 2.21 needed by Jackson 3.1.7, so the app fails to start' + - boot: '3.5.13' + jackson: '' + expect: pass + why: 'annotations 2.21 is what Jackson 3.1.7 needs' + - boot: '3.5.16' + jackson: '3.2.3' + expect: fail + why: 'Kotlin 1.9 forced by Boot (first of two blockers; annotations 2.21 < 2.22 is the second)' + env: + COMPAT_ARGS: -PcompatBootVersion=${{ matrix.boot }} ${{ matrix.jackson && format('-PcompatJacksonVersion={0}', matrix.jackson) || '' }} + + steps: + - name: Checkout + uses: actions/checkout@v6 + + - name: Set up Zulu JDK 21 + uses: actions/setup-java@v5 + with: + distribution: "zulu" + java-version: "21" + + - name: Show resolved versions + id: versions + run: | + resolved() { + local out + out=$(./gradlew -q :conductor-client-spring:dependencyInsight \ + --configuration bootCompatTestRuntimeClasspath --dependency "$1" $COMPAT_ARGS) + echo "$out" | awk 'NR==1 {print $1}' | awk -F: '{print $NF}' + } + annotations=$(resolved com.fasterxml.jackson.core:jackson-annotations) + engine=$(resolved tools.jackson.core:jackson-databind) + kotlin=$(resolved org.jetbrains.kotlin:kotlin-stdlib) + echo "jackson-annotations=$annotations jackson-databind=$engine kotlin-stdlib=$kotlin" + { + echo "annotations=$annotations" + echo "engine=$engine" + echo "kotlin=$kotlin" + } >> "$GITHUB_OUTPUT" + + - name: Run Boot 3 compatibility tests + id: tests + run: ./gradlew :conductor-client-spring:bootCompatTest $COMPAT_ARGS + + - name: Summary + if: always() + env: + BOOT: ${{ matrix.boot }} + EXPECT: ${{ matrix.expect }} + WHY: ${{ matrix.why }} + OUTCOME: ${{ steps.tests.outcome }} + ANNOTATIONS: ${{ steps.versions.outputs.annotations }} + ENGINE: ${{ steps.versions.outputs.engine }} + KOTLIN: ${{ steps.versions.outputs.kotlin }} + run: | + actual=$([ "$OUTCOME" = success ] && echo pass || echo fail) + verdict=$([ "$actual" = "$EXPECT" ] && echo "as predicted" || echo "UNEXPECTED") + results=conductor-client-spring/build/test-results/bootCompatTest/ + errors=$(grep -rhoE 'NoClassDefFoundError: [A-Za-z0-9/_$]+' "$results" 2>/dev/null \ + | sort -u | paste -sd ',' - || true) + sdk_message=$(grep -rhoE 'Conductor SDK could not start Jackson[^<&"]*' "$results" 2>/dev/null \ + | sort -u | head -1 || true) + { + echo "### Boot $BOOT: $actual ($verdict)" + echo + echo "| Boot | Jackson engine | jackson-annotations | Kotlin | Expected | Actual | Error |" + echo "|---|---|---|---|---|---|---|" + echo "| $BOOT | $ENGINE | $ANNOTATIONS | $KOTLIN | $EXPECT | $actual | ${errors:-none} |" + echo + echo "Why: $WHY" + if [ -n "$sdk_message" ]; then + echo + echo "What the user sees:" + echo + echo "> $sdk_message" + fi + } >> "$GITHUB_STEP_SUMMARY" + cat "$GITHUB_STEP_SUMMARY" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ecca05d7a..eb336ec7f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,6 +4,8 @@ on: push: branches: - main + # Demo only: shows bootCompatTest running in the normal build. Remove before merging. + - demo/boot3-jackson-annotations pull_request: branches: - main @@ -148,7 +150,7 @@ jobs: if: always() uses: mikepenz/action-junit-report@v6 with: - report_paths: '**/build/test-results/test/TEST-*.xml' + report_paths: '**/build/test-results/{test,bootCompatTest}/TEST-*.xml' - name: Check Tests Status if: steps.tests.outcome == 'failure' diff --git a/.github/workflows/worker-compat-demo.yml b/.github/workflows/worker-compat-demo.yml new file mode 100644 index 000000000..613797dba --- /dev/null +++ b/.github/workflows/worker-compat-demo.yml @@ -0,0 +1,108 @@ +# Demo for PR #189 (Jackson 3), issues 2 and 3: the same worker tests in four setups. Each test +# asserts the SDK 6.0.2 (Jackson 2) behavior, so a red test is a change a worker author would see. +# 1. SDK 6.0.2 -> baseline +# 2. PR #189 as submitted (db7b12a) -> what users get today from the PR +# 3. PR + SDK fixes (this branch) -> what the SDK alone can restore +# 4. PR + SDK fixes + migrated user code -> after users add Jackson 3 annotations +name: Worker compatibility demo + +on: + push: + branches: + - demo/boot3-jackson-annotations + +jobs: + worker-compat: + name: ${{ matrix.label }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - label: 1. SDK 6.0.2 (released, Jackson 2) + sdk: '6.0.2' + sdk_source: none + user_code: jackson2 + expect_pass: 8 + - label: 2. PR 189 as submitted (Jackson 3) + sdk: '0.0.0-pr189-asis' + sdk_source: db7b12ae0bb6764b0f023eabebf3a34444fb9e48 + user_code: jackson2 + expect_pass: 0 + - label: 3. PR 189 + SDK fixes + sdk: '0.0.0-pr189-fixed' + sdk_source: this-branch + user_code: jackson2 + expect_pass: 6 + - label: 4. PR 189 + SDK fixes + migrated user code + sdk: '0.0.0-pr189-fixed' + sdk_source: this-branch + user_code: migrated + expect_pass: 8 + env: + DEMO_M2: ${{ github.workspace }}/build/demo-m2 + + steps: + - name: Checkout + uses: actions/checkout@v6 + + - name: Checkout the PR as submitted + if: matrix.sdk_source != 'none' && matrix.sdk_source != 'this-branch' + uses: actions/checkout@v6 + with: + ref: ${{ matrix.sdk_source }} + path: sdk-src + + - name: Set up Zulu JDK 21 + uses: actions/setup-java@v5 + with: + distribution: "zulu" + java-version: "21" + + - name: Publish the SDK under test to a local Maven repo + if: matrix.sdk_source != 'none' + run: | + dir=$([ "${{ matrix.sdk_source }}" = this-branch ] && echo . || echo sdk-src) + cd "$dir" + ./gradlew :conductor-client:publishToMavenLocal -Pversion=${{ matrix.sdk }} -Dmaven.repo.local="$DEMO_M2" + + - name: Run worker tests + id: tests + run: > + ./gradlew -p demo/worker-compat test + -PsdkVersion=${{ matrix.sdk }} + -PuserCode=${{ matrix.user_code }} + -Dmaven.repo.local="$DEMO_M2" + + - name: Summary + if: always() + env: + LABEL: ${{ matrix.label }} + USER_CODE: ${{ matrix.user_code }} + EXPECT_PASS: ${{ matrix.expect_pass }} + run: | + python3 - <<'EOF' >> "$GITHUB_STEP_SUMMARY" + import glob, os, xml.etree.ElementTree as ET + rows = [] + for path in glob.glob('demo/worker-compat/build/test-results/test/*.xml'): + for case in ET.parse(path).getroot().iter('testcase'): + failure = case.find('failure') + detail = '' + if failure is not None: + detail = ' '.join((failure.get('message') or '').split())[:160] + detail = detail.replace('|', '\\|') + rows.append((case.get('name'), failure is None, detail)) + rows.sort() + passed = sum(1 for _, ok, _ in rows if ok) + expected = int(os.environ['EXPECT_PASS']) + verdict = 'as predicted' if passed == expected else f'UNEXPECTED, predicted {expected}' + print(f"### {os.environ['LABEL']}: {passed}/{len(rows)} pass ({verdict})") + print() + print(f"User code: `src/userCode/{os.environ['USER_CODE']}`") + print() + print("| Behavior (as in SDK 6.0.2) | Result | What happened instead |") + print("|---|---|---|") + for name, ok, detail in rows: + print(f"| {name} | {'✅' if ok else '❌'} | {detail} |") + EOF + cat "$GITHUB_STEP_SUMMARY" diff --git a/README.md b/README.md index 580147832..b1ad7c429 100644 --- a/README.md +++ b/README.md @@ -204,6 +204,7 @@ For worker patterns, workflow definitions, and testing, continue with the [core | Task remains `SCHEDULED` | A worker is polling the exact task type and has enough threads. | | Authentication failure | `CONDUCTOR_AUTH_KEY` and `CONDUCTOR_AUTH_SECRET` are set for the target server. | | AI agent cannot call a model | The server—not only the client process—has a configured LLM provider and model. | +| `Conductor SDK could not start Jackson` at startup | On Spring Boot 3, use 3.5.13+ or set `jackson-bom.version` to 2.21.x; see [older Spring Boot 3 versions](conductor-client-spring/README.md#older-spring-boot-3-versions). | ## Support and project policies diff --git a/conductor-client-spring/README.md b/conductor-client-spring/README.md index 023b860e0..6e8e1923b 100644 --- a/conductor-client-spring/README.md +++ b/conductor-client-spring/README.md @@ -2,7 +2,7 @@ Spring Boot 3 auto-configuration for the Conductor core client, workflow SDK, and Java workers. -**Prerequisites:** Java 21+, Spring Boot 3, and a running [OSS or Orkes Conductor server](../docs/connection-authentication.md). For Spring Boot 4, use [the Boot 4 module](../conductor-client-spring-boot4/README.md). +**Prerequisites:** Java 21+, Spring Boot 3.5.13+ (see [Older Spring Boot 3 versions](#older-spring-boot-3-versions)), and a running [OSS or Orkes Conductor server](../docs/connection-authentication.md). For Spring Boot 4, use [the Boot 4 module](../conductor-client-spring-boot4/README.md). ## Install @@ -20,6 +20,24 @@ implementation 'org.conductoross:conductor-client-spring:' ``` +### Older Spring Boot 3 versions + +The SDK uses Jackson 3, which needs `com.fasterxml.jackson.core:jackson-annotations` 2.21 or later. Spring Boot's dependency management picks that version for your app, and Spring Boot 3.5.12 and earlier pick an older one. The app then fails at startup with `Conductor SDK could not start Jackson: missing class com/fasterxml/jackson/annotation/...`. + +Upgrade to Spring Boot 3.5.13 or later, or override Boot's Jackson version: + +```xml + + + 2.21.4 + +``` + +```groovy +// Gradle, with the io.spring.dependency-management plugin +ext['jackson-bom.version'] = '2.21.4' +``` + ## Configure ```properties diff --git a/conductor-client-spring/build.gradle b/conductor-client-spring/build.gradle index 4fda65695..eac3d0bba 100644 --- a/conductor-client-spring/build.gradle +++ b/conductor-client-spring/build.gradle @@ -32,3 +32,45 @@ java { test { useJUnitPlatform() } + +// Runs the starter on the dependency versions a real Spring Boot app resolves. +// enforcedPlatform makes Boot's BOM win, like spring-boot-starter-parent does, +// so jackson-annotations comes from Boot rather than from our Jackson 3 BOM. +// -PcompatBootVersion=3.5.12 Boot BOM to resolve against +// -PcompatJacksonVersion=3.2.3 optional: force a different Jackson 3 engine +def compatBoot = findProperty('compatBootVersion') ?: '3.5.13' +def compatJackson = findProperty('compatJacksonVersion') + +testing { + suites { + bootCompatTest(JvmTestSuite) { + useJUnitJupiter() + dependencies { + implementation project() + implementation enforcedPlatform("org.springframework.boot:spring-boot-dependencies:${compatBoot}") + implementation 'org.springframework.boot:spring-boot-starter-test' + if (compatJackson) { + ['tools.jackson.core:jackson-databind', + 'tools.jackson.core:jackson-core', + 'tools.jackson.module:jackson-module-kotlin'].each { coord -> + implementation(coord) { version { strictly compatJackson } } + } + } + } + targets.all { + testTask.configure { + // Fresh JVM per test class so each one reports the root + // NoClassDefFoundError, not "Could not initialize class". + forkEvery = 1 + testLogging { + events 'passed', 'failed' + exceptionFormat 'full' + } + } + } + } + } +} + +// Run the suite (on the default, oldest supported Boot 3) in every build. +tasks.named('check') { dependsOn testing.suites.bootCompatTest } diff --git a/conductor-client-spring/src/bootCompatTest/java/com/netflix/conductor/client/spring/compat/Boot3StartupTest.java b/conductor-client-spring/src/bootCompatTest/java/com/netflix/conductor/client/spring/compat/Boot3StartupTest.java new file mode 100644 index 000000000..2853fa108 --- /dev/null +++ b/conductor-client-spring/src/bootCompatTest/java/com/netflix/conductor/client/spring/compat/Boot3StartupTest.java @@ -0,0 +1,40 @@ +/* + * Copyright 2026 Conductor Authors. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 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 com.netflix.conductor.client.spring.compat; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; + +import com.netflix.conductor.client.http.ConductorClient; +import com.netflix.conductor.client.spring.ConductorClientAutoConfiguration; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Does a Boot app using the starter start up? ConductorClient builds its Jackson + * mapper in its constructor, so an incompatible jackson-annotations jar fails here. + */ +class Boot3StartupTest { + + @Test + void applicationContextStarts() { + new ApplicationContextRunner() + .withConfiguration(AutoConfigurations.of(ConductorClientAutoConfiguration.class)) + .withPropertyValues("conductor.client.base-path=http://localhost:8080/api") + .run(context -> { + assertThat(context).hasNotFailed(); + assertThat(context).hasSingleBean(ConductorClient.class); + }); + } +} diff --git a/conductor-client-spring/src/bootCompatTest/java/com/netflix/conductor/client/spring/compat/Boot3WorkerTest.java b/conductor-client-spring/src/bootCompatTest/java/com/netflix/conductor/client/spring/compat/Boot3WorkerTest.java new file mode 100644 index 000000000..bbc1adfe2 --- /dev/null +++ b/conductor-client-spring/src/bootCompatTest/java/com/netflix/conductor/client/spring/compat/Boot3WorkerTest.java @@ -0,0 +1,61 @@ +/* + * Copyright 2026 Conductor Authors. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 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 com.netflix.conductor.client.spring.compat; + +import java.util.Map; + +import org.junit.jupiter.api.Test; + +import com.netflix.conductor.common.metadata.tasks.Task; +import com.netflix.conductor.common.metadata.tasks.TaskResult; +import com.netflix.conductor.sdk.workflow.executor.task.AnnotatedWorker; +import com.netflix.conductor.sdk.workflow.task.InputParam; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Can a worker do its job? Task input is bound to a POJO and the returned POJO is + * converted back to output data, both through the SDK's Jackson mapper. + */ +class Boot3WorkerTest { + + public static class Person { + public String name; + } + + public static class Greeting { + public String greeting; + } + + public static class Greeter { + public Greeting greet(@InputParam("person") Person person) { + Greeting result = new Greeting(); + result.greeting = "Hello " + person.name; + return result; + } + } + + @Test + void annotatedWorkerRoundTrip() throws Exception { + AnnotatedWorker worker = new AnnotatedWorker( + "greet", Greeter.class.getMethod("greet", Person.class), new Greeter()); + Task task = new Task(); + task.setStatus(Task.Status.IN_PROGRESS); + task.setInputData(Map.of("person", Map.of("name", "Ada"))); + + TaskResult result = worker.execute(task); + + assertThat(result.getStatus()).isEqualTo(TaskResult.Status.COMPLETED); + assertThat(result.getOutputData()).containsEntry("greeting", "Hello Ada"); + } +} diff --git a/conductor-client/src/main/java/com/netflix/conductor/common/config/ObjectMapperProvider.java b/conductor-client/src/main/java/com/netflix/conductor/common/config/ObjectMapperProvider.java index 1ba5e26bf..276264d75 100644 --- a/conductor-client/src/main/java/com/netflix/conductor/common/config/ObjectMapperProvider.java +++ b/conductor-client/src/main/java/com/netflix/conductor/common/config/ObjectMapperProvider.java @@ -12,16 +12,29 @@ */ package com.netflix.conductor.common.config; +import java.io.InputStream; +import java.util.Properties; + import com.fasterxml.jackson.annotation.JsonInclude; +import tools.jackson.core.JsonGenerator; import tools.jackson.databind.DeserializationFeature; +import tools.jackson.databind.MapperFeature; import tools.jackson.databind.ObjectMapper; +import tools.jackson.databind.SerializationContext; import tools.jackson.databind.SerializationFeature; +import tools.jackson.databind.ValueSerializer; import tools.jackson.databind.cfg.DateTimeFeature; +import tools.jackson.databind.cfg.EnumFeature; import tools.jackson.databind.json.JsonMapper; +import tools.jackson.databind.module.SimpleModule; import tools.jackson.module.kotlin.KotlinModule; public class ObjectMapperProvider { + // Keep in sync with jacksonBom in versions.gradle: the jackson-annotations release that + // the Jackson 3 engine was built against. + private static final String MIN_JACKSON_ANNOTATIONS = "2.21"; + private static final ObjectMapper objectMapper = _getObjectMapper(); public ObjectMapper getObjectMapper() { @@ -37,19 +50,149 @@ public ObjectMapper getObjectMapper() { *

WRITE_DATES_AS_TIMESTAMPS is enabled to keep the numeric date encoding that Jackson 2 * produced with JavaTimeModule. Jackson 3 defaults to ISO-8601 strings, which would change the * payload format seen by the server and stored task/workflow documents. + * + *

The enum, duration, getter-as-setter and final-field settings restore other Jackson 2 + * defaults, so worker inputs and outputs keep the shape they had with SDK 6.x. */ private static ObjectMapper _getObjectMapper() { - return JsonMapper.builder() - .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) - .disable(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES) - .disable(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES) - .disable(SerializationFeature.FAIL_ON_EMPTY_BEANS) - .enable(DateTimeFeature.WRITE_DATES_AS_TIMESTAMPS) - .changeDefaultPropertyInclusion( - value -> - JsonInclude.Value.construct( - JsonInclude.Include.NON_NULL, JsonInclude.Include.ALWAYS)) - .addModule(new KotlinModule.Builder().build()) - .build(); + try { + JsonMapper.Builder builder = + JsonMapper.builder() + .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) + .disable(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES) + .disable(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES) + .disable(SerializationFeature.FAIL_ON_EMPTY_BEANS) + .enable(DateTimeFeature.WRITE_DATES_AS_TIMESTAMPS) + .enable(DateTimeFeature.WRITE_DURATIONS_AS_TIMESTAMPS) + .disable( + EnumFeature.READ_ENUMS_USING_TO_STRING, + EnumFeature.WRITE_ENUMS_USING_TO_STRING) + .enable( + MapperFeature.USE_GETTERS_AS_SETTERS, + MapperFeature.ALLOW_FINAL_FIELDS_AS_MUTATORS) + .changeDefaultPropertyInclusion( + value -> + JsonInclude.Value.construct( + JsonInclude.Include.NON_NULL, + JsonInclude.Include.ALWAYS)) + .addModule(new KotlinModule.Builder().build()); + SimpleModule jackson2JsonNode = jackson2JsonNodeModule(); + if (jackson2JsonNode != null) { + builder.addModule(jackson2JsonNode); + } + ObjectMapper mapper = builder.build(); + selfCheck(mapper); + return mapper; + } catch (RuntimeException | LinkageError e) { + LinkageError missing = findLinkageError(e); + if (missing == null) { + throw e; + } + throw new IllegalStateException(incompatibleJacksonMessage(missing), e); + } + } + + /** + * Some classes Jackson needs are only loaded the first time it inspects a bean, so convert + * one here. An incompatible classpath then fails at startup, not on the first task. + */ + private static void selfCheck(ObjectMapper mapper) { + SelfCheck value = new SelfCheck(); + value.value = "ok"; + mapper.readValue(mapper.writeValueAsString(value), SelfCheck.class); + } + + public static class SelfCheck { + public String value; + } + + /** + * Workers often put a Jackson 2 JsonNode (for example a REST client response) into task output. + * Jackson 3 does not know that type and would write its getters, so write the JSON it holds. + */ + @SuppressWarnings({"unchecked", "rawtypes"}) + private static SimpleModule jackson2JsonNodeModule() { + Class nodeType; + try { + nodeType = + Class.forName( + "com.fasterxml.jackson.databind.JsonNode", + false, + ObjectMapperProvider.class.getClassLoader()); + } catch (ClassNotFoundException | LinkageError e) { + return null; + } + SimpleModule module = new SimpleModule("conductor-jackson2-json-node"); + module.addSerializer((Class) nodeType, new Jackson2JsonNodeSerializer()); + return module; + } + + private static class Jackson2JsonNodeSerializer extends ValueSerializer { + @Override + public void serialize(Object value, JsonGenerator gen, SerializationContext ctxt) { + ctxt.writeValue(gen, JsonMapper.shared().readTree(value.toString())); + } + } + + private static LinkageError findLinkageError(Throwable t) { + for (Throwable cause = t; cause != null; cause = cause.getCause()) { + if (cause instanceof LinkageError linkageError) { + return linkageError; + } + } + return null; + } + + private static String incompatibleJacksonMessage(LinkageError e) { + String missing = String.valueOf(e.getMessage()); + String hint; + if (missing.startsWith("com/fasterxml/jackson/annotation/")) { + hint = "jackson-annotations is older than this Jackson version needs."; + } else if (missing.startsWith("kotlin/")) { + hint = "kotlin-stdlib is older than this Jackson version needs."; + } else { + hint = "A Jackson dependency is older than this Jackson version needs."; + } + return "Conductor SDK could not start Jackson: missing class " + + missing + + ". " + + hint + + " Found jackson-databind " + + mavenVersion("tools.jackson.core", "jackson-databind") + + ", jackson-annotations " + + mavenVersion("com.fasterxml.jackson.core", "jackson-annotations") + + ", kotlin-stdlib " + + kotlinVersion() + + ". A dependency BOM most likely forced an older version; in a Spring Boot 3 app," + + " Boot's BOM manages jackson-annotations and Kotlin. This SDK needs" + + " jackson-annotations " + + MIN_JACKSON_ANNOTATIONS + + " or later: use Spring Boot 3.5.13 or later, or set the jackson-bom.version" + + " property to " + + MIN_JACKSON_ANNOTATIONS + + ".x."; + } + + private static String mavenVersion(String group, String artifact) { + String path = "META-INF/maven/" + group + "/" + artifact + "/pom.properties"; + try (InputStream in = ObjectMapperProvider.class.getClassLoader().getResourceAsStream(path)) { + if (in == null) { + return "unknown"; + } + Properties properties = new Properties(); + properties.load(in); + return properties.getProperty("version", "unknown"); + } catch (Exception | LinkageError ignored) { + return "unknown"; + } + } + + private static String kotlinVersion() { + try { + String version = Class.forName("kotlin.Unit").getPackage().getImplementationVersion(); + return version == null ? "unknown" : version; + } catch (Exception | LinkageError ignored) { + return "not on classpath"; + } } } diff --git a/demo/worker-compat/build.gradle b/demo/worker-compat/build.gradle new file mode 100644 index 000000000..9c301c308 --- /dev/null +++ b/demo/worker-compat/build.gradle @@ -0,0 +1,53 @@ +// Worker code compiled against a chosen conductor-client release. +// -PsdkVersion=6.0.2 released SDK (Jackson 2), from Maven Central +// -PsdkVersion=0.0.0-pr189-... an SDK published with publishToMavenLocal +// -PuserCode=jackson2|migrated user classes as written for 6.x, or with Jackson 3 +// annotations added (src/userCode//java) +plugins { + id 'java' +} + +def sdkVersion = findProperty('sdkVersion') ?: '6.0.2' +def userCode = findProperty('userCode') ?: 'jackson2' + +sourceSets { + test { + java { + srcDir "src/userCode/${userCode}/java" + } + } +} + +repositories { + mavenLocal() + mavenCentral() +} + +java { + sourceCompatibility = 21 + targetCompatibility = 21 +} + +dependencies { + testImplementation "org.conductoross:conductor-client:${sdkVersion}" + // The worker app's own Jackson 2, e.g. from Spring Boot 3 or a REST client. + testImplementation 'com.fasterxml.jackson.core:jackson-databind:2.18.6' + if (userCode == 'migrated') { + // Jackson 3 annotations only need to compile. At runtime on SDK 6.x they are absent, + // and the JVM ignores annotations whose classes are missing. + testCompileOnly 'tools.jackson.core:jackson-databind:3.1.7' + } + + testImplementation platform('org.junit:junit-bom:5.11.4') + testImplementation 'org.junit.jupiter:junit-jupiter' + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' + testImplementation 'org.assertj:assertj-core:3.26.3' +} + +test { + useJUnitPlatform() + testLogging { + events 'passed', 'failed' + exceptionFormat 'short' + } +} diff --git a/demo/worker-compat/settings.gradle b/demo/worker-compat/settings.gradle new file mode 100644 index 000000000..2bb91554f --- /dev/null +++ b/demo/worker-compat/settings.gradle @@ -0,0 +1,2 @@ +// Standalone build: depends on a published conductor-client, like a user's project. +rootProject.name = 'worker-compat' diff --git a/demo/worker-compat/src/test/java/workercompat/Tier.java b/demo/worker-compat/src/test/java/workercompat/Tier.java new file mode 100644 index 000000000..a251a5528 --- /dev/null +++ b/demo/worker-compat/src/test/java/workercompat/Tier.java @@ -0,0 +1,23 @@ +/* + * Copyright 2026 Conductor Authors. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 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 workercompat; + +public enum Tier { + GOLD, + SILVER; + + @Override + public String toString() { + return name().toLowerCase(); + } +} diff --git a/demo/worker-compat/src/test/java/workercompat/WorkerCompatTest.java b/demo/worker-compat/src/test/java/workercompat/WorkerCompatTest.java new file mode 100644 index 000000000..696eb0c61 --- /dev/null +++ b/demo/worker-compat/src/test/java/workercompat/WorkerCompatTest.java @@ -0,0 +1,205 @@ +/* + * Copyright 2026 Conductor Authors. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 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 workercompat; + +import java.net.InetSocketAddress; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import com.netflix.conductor.client.http.ConductorClient; +import com.netflix.conductor.client.http.TaskClient; +import com.netflix.conductor.common.metadata.tasks.Task; +import com.netflix.conductor.common.metadata.tasks.TaskResult; +import com.netflix.conductor.sdk.workflow.executor.task.AnnotatedWorker; +import com.netflix.conductor.sdk.workflow.task.InputParam; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.sun.net.httpserver.HttpServer; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + +/** + * Ordinary worker code. Every test asserts what the Jackson 2 SDK (6.0.2) does, so it passes on + * 6.0.2 and shows what changes for the same code on the Jackson 3 SDK. + * + *

Inputs are checked on the object the worker method receives. Outputs are checked on the JSON + * that TaskClient.updateTask() actually sends, captured by a fake server. + * + *

Customer and Shipment carry Jackson 2 annotations and come from src/userCode/{jackson2,migrated}, + * picked with -PuserCode. Tier is in Tier.java. + */ +class WorkerCompatTest { + + // ---- Worker types, as a user would write them ---- + + public static class Order { + public Tier tier; + public final String region = null; + private final List items = new ArrayList<>(); + + public List getItems() { + return items; + } + } + + public static class Workers { + Order order; + Customer customer; + + public void takeOrder(@InputParam("order") Order order) { + this.order = order; + } + + public void takeCustomer(@InputParam("customer") Customer customer) { + this.customer = customer; + } + + public Shipment ship() { + return new Shipment(); + } + + // A worker that returns a REST response it parsed with its own Jackson 2. + public Map callApi() throws Exception { + Map output = new HashMap<>(); + output.put("response", new ObjectMapper().readTree("{\"status\":\"ok\",\"count\":1}")); + return output; + } + } + + // ---- Fake Conductor server that records task updates ---- + + private HttpServer server; + private final List requestBodies = new ArrayList<>(); + private final Workers workers = new Workers(); + + @BeforeEach + void startServer() throws Exception { + server = HttpServer.create(new InetSocketAddress("127.0.0.1", 0), 0); + server.createContext("/", exchange -> { + requestBodies.add(new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8)); + exchange.sendResponseHeaders(200, -1); + exchange.close(); + }); + server.start(); + } + + @AfterEach + void stopServer() { + server.stop(0); + } + + // ---- Issue 2: inputs ---- + + @Test + @DisplayName("Issue 2 input: enum with custom toString() binds from \"GOLD\"") + void enumBindsFromName() { + run("takeOrder", Map.of("order", Map.of("tier", "GOLD"))); + assertThat(workers.order.tier).isEqualTo(Tier.GOLD); + } + + @Test + @DisplayName("Issue 2 input: getter-only list is filled") + void getterOnlyListIsFilled() { + run("takeOrder", Map.of("order", Map.of("items", List.of("a", "b")))); + assertThat(workers.order.getItems()).containsExactly("a", "b"); + } + + @Test + @DisplayName("Issue 2 input: final field is set") + void finalFieldIsSet() { + run("takeOrder", Map.of("order", Map.of("region", "eu"))); + assertThat(workers.order.region).isEqualTo("eu"); + } + + @Test + @DisplayName("Issue 2 input: Jackson 2 @JsonNaming is applied (user code change needed on Jackson 3)") + void jackson2JsonNamingIsApplied() { + run("takeCustomer", Map.of("customer", Map.of("customer_id", "c1"))); + assertThat(workers.customer.customerId).isEqualTo("c1"); + } + + // ---- Issue 2: outputs ---- + + @Test + @DisplayName("Issue 2 output: enum is sent by name (\"GOLD\")") + void enumIsSentByName() { + assertThat(sentOutput("ship").get("tier").asText()).isEqualTo("GOLD"); + } + + @Test + @DisplayName("Issue 2 output: Duration is sent as a number of seconds (90.0)") + void durationIsSentAsNumber() { + JsonNode timeout = sentOutput("ship").get("timeout"); + assertThat(timeout.isNumber()).as("timeout sent as %s", timeout).isTrue(); + assertThat(timeout.asDouble()).isEqualTo(90.0); + } + + @Test + @DisplayName("Issue 2 output: Jackson 2 @JsonSerialize is applied (user code change needed on Jackson 3)") + void jackson2JsonSerializeIsApplied() { + JsonNode trackingId = sentOutput("ship").get("trackingId"); + assertThat(trackingId.isTextual()).as("trackingId sent as %s", trackingId).isTrue(); + } + + // ---- Issue 3 ---- + + @Test + @DisplayName("Issue 3 output: Jackson 2 JsonNode is sent as its JSON") + void jackson2JsonNodeIsSentAsJson() throws Exception { + assertThat(sentOutput("callApi").get("response")) + .isEqualTo(new ObjectMapper().readTree("{\"status\":\"ok\",\"count\":1}")); + } + + // ---- Helpers ---- + + private TaskResult run(String method, Map input) { + try { + var workerMethod = java.util.Arrays.stream(Workers.class.getMethods()) + .filter(m -> m.getName().equals(method)) + .findFirst() + .orElseThrow(); + Task task = new Task(); + task.setTaskId("task-1"); + task.setWorkflowInstanceId("wf-1"); + task.setStatus(Task.Status.IN_PROGRESS); + task.setInputData(new HashMap<>(input)); + return new AnnotatedWorker(method, workerMethod, workers).execute(task); + } catch (Exception e) { + return fail("worker failed: " + e + (e.getCause() != null ? " / cause: " + e.getCause() : "")); + } + } + + /** Runs the worker, sends its result with TaskClient, and returns the outputData the server got. */ + private JsonNode sentOutput(String method) { + TaskResult result = run(method, Map.of()); + ConductorClient client = ConductorClient.builder() + .basePath("http://127.0.0.1:" + server.getAddress().getPort() + "/api") + .build(); + new TaskClient(client).updateTask(result); + try { + return new ObjectMapper().readTree(requestBodies.get(requestBodies.size() - 1)).get("outputData"); + } catch (Exception e) { + return fail("could not read request body: " + e); + } + } +} diff --git a/demo/worker-compat/src/userCode/jackson2/java/workercompat/Customer.java b/demo/worker-compat/src/userCode/jackson2/java/workercompat/Customer.java new file mode 100644 index 000000000..62015fb10 --- /dev/null +++ b/demo/worker-compat/src/userCode/jackson2/java/workercompat/Customer.java @@ -0,0 +1,22 @@ +/* + * Copyright 2026 Conductor Authors. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 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 workercompat; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; + +/** User code as written for SDK 6.x: Jackson 2 annotation only. */ +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class Customer { + public String customerId; +} diff --git a/demo/worker-compat/src/userCode/jackson2/java/workercompat/Shipment.java b/demo/worker-compat/src/userCode/jackson2/java/workercompat/Shipment.java new file mode 100644 index 000000000..e58c07620 --- /dev/null +++ b/demo/worker-compat/src/userCode/jackson2/java/workercompat/Shipment.java @@ -0,0 +1,27 @@ +/* + * Copyright 2026 Conductor Authors. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 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 workercompat; + +import java.time.Duration; + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; + +/** User code as written for SDK 6.x: Jackson 2 annotation only. */ +public class Shipment { + public Tier tier = Tier.GOLD; + public Duration timeout = Duration.ofSeconds(90); + + @JsonSerialize(using = ToStringSerializer.class) + public long trackingId = 42; +} diff --git a/demo/worker-compat/src/userCode/migrated/java/workercompat/Customer.java b/demo/worker-compat/src/userCode/migrated/java/workercompat/Customer.java new file mode 100644 index 000000000..89606a426 --- /dev/null +++ b/demo/worker-compat/src/userCode/migrated/java/workercompat/Customer.java @@ -0,0 +1,25 @@ +/* + * Copyright 2026 Conductor Authors. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 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 workercompat; + +/** + * User code migrated for the Jackson 3 SDK: the Jackson 3 annotation is added next to the + * Jackson 2 one. Each Jackson reads only its own, so this works on SDK 6.x and on Jackson 3. + */ +@com.fasterxml.jackson.databind.annotation.JsonNaming( + com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy.class) +@tools.jackson.databind.annotation.JsonNaming( + tools.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy.class) +public class Customer { + public String customerId; +} diff --git a/demo/worker-compat/src/userCode/migrated/java/workercompat/Shipment.java b/demo/worker-compat/src/userCode/migrated/java/workercompat/Shipment.java new file mode 100644 index 000000000..f1209ffd5 --- /dev/null +++ b/demo/worker-compat/src/userCode/migrated/java/workercompat/Shipment.java @@ -0,0 +1,30 @@ +/* + * Copyright 2026 Conductor Authors. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 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 workercompat; + +import java.time.Duration; + +/** + * User code migrated for the Jackson 3 SDK: the Jackson 3 annotation is added next to the + * Jackson 2 one. Each Jackson reads only its own, so this works on SDK 6.x and on Jackson 3. + */ +public class Shipment { + public Tier tier = Tier.GOLD; + public Duration timeout = Duration.ofSeconds(90); + + @com.fasterxml.jackson.databind.annotation.JsonSerialize( + using = com.fasterxml.jackson.databind.ser.std.ToStringSerializer.class) + @tools.jackson.databind.annotation.JsonSerialize( + using = tools.jackson.databind.ser.std.ToStringSerializer.class) + public long trackingId = 42; +} diff --git a/versions.gradle b/versions.gradle index 7f4f144f6..811e9a1e6 100644 --- a/versions.gradle +++ b/versions.gradle @@ -2,6 +2,10 @@ ext { versions = [ okHttp : '4.12.0', guava : '33.6.0-jre', + // Spring Boot 3 apps get jackson-annotations (max 2.21, Boot 3.5.13+) and Kotlin + // (1.9) from Boot's BOM. Jackson 3.2+ needs annotations 2.22 and Kotlin 2.x, so + // moving past 3.1.x drops Boot 3 support. Keep MIN_JACKSON_ANNOTATIONS in + // ObjectMapperProvider in sync. jacksonBom : '3.1.7', archaius : '0.7.12', slf4j : '1.7.36',