-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0001-Replace-Jackson-with-Moshi.patch
More file actions
2032 lines (1974 loc) · 79.3 KB
/
Copy path0001-Replace-Jackson-with-Moshi.patch
File metadata and controls
2032 lines (1974 loc) · 79.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
From b0e756ce00e3de1fe8c039ba2fb997f3dec4096a Mon Sep 17 00:00:00 2001
From: Marius Volkhart <marius.volkhart@pkware.com>
Date: Thu, 21 May 2026 14:36:55 -0400
Subject: [PATCH] Replace Jackson with Moshi
Swap Jackson for Moshi as the default JSON library. MoshiJsonPayloadConverter
replaces JacksonJsonPayloadConverter in STANDARD_PAYLOAD_CONVERTERS.
Internal POJOs use @Json(name=...) annotations instead of @JsonProperty.
OperationTokenUtil and NexusUtil use Moshi adapters instead of ObjectMapper.
@DurationMillis qualifier ensures internal Duration fields always serialize
as integer millis regardless of user-provided Duration adapters.
Removes Jackson 2, Jackson 3, jackson-datatype-jsr310, jackson-datatype-jdk8,
jackson-module-kotlin. Excludes temporal-envconfig (jackson-dataformat-toml).
---
settings.gradle | 22 +-
temporal-bom/build.gradle | 7 -
temporal-sdk/build.gradle | 100 +-------
.../Jackson3JsonPayloadConverterTest.java | 216 ------------------
.../common/converter/CodecDataConverter.java | 9 +-
.../common/converter/DataConverter.java | 4 +-
.../converter/DefaultDataConverter.java | 2 +-
.../common/converter/DurationMillis.java | 19 ++
.../converter/DurationMillisAdapter.java | 25 ++
.../Jackson3JsonPayloadConverter.java | 50 ----
.../JacksonJsonPayloadConverter.java | 141 ------------
.../converter/MoshiJsonPayloadConverter.java | 131 +++++++++++
.../converter/OperationTokenTypeAdapter.java | 21 ++
.../converter/OptionalAdapterFactory.java | 57 +++++
.../common/converter/PayloadConverter.java | 4 +-
.../common/converter/StandardAdapters.java | 130 +++++++++++
.../internal/common/InternalUtils.java | 4 +-
.../temporal/internal/common/NexusUtil.java | 31 ++-
.../history/LocalActivityMarkerMetadata.java | 12 +-
.../internal/nexus/OperationToken.java | 23 +-
.../internal/nexus/OperationTokenType.java | 5 -
.../internal/nexus/OperationTokenUtil.java | 21 +-
.../temporal/payload/codec/PayloadCodec.java | 4 +-
.../Jackson3JsonPayloadConverter.java | 134 -----------
.../ActivityHeartbeatThrottlingTest.java | 4 +-
.../JacksonJsonPayloadConverterTest.java | 158 -------------
.../MoshiJsonPayloadConverterTest.java | 105 +++++++++
.../internal/nexus/WorkflowRunTokenTest.java | 37 ++-
.../java/io/temporal/workflow/MemoTest.java | 2 +-
29 files changed, 576 insertions(+), 902 deletions(-)
delete mode 100644 temporal-sdk/src/jackson3Tests/java/io/temporal/common/converter/Jackson3JsonPayloadConverterTest.java
create mode 100644 temporal-sdk/src/main/java/io/temporal/common/converter/DurationMillis.java
create mode 100644 temporal-sdk/src/main/java/io/temporal/common/converter/DurationMillisAdapter.java
delete mode 100644 temporal-sdk/src/main/java/io/temporal/common/converter/Jackson3JsonPayloadConverter.java
delete mode 100644 temporal-sdk/src/main/java/io/temporal/common/converter/JacksonJsonPayloadConverter.java
create mode 100644 temporal-sdk/src/main/java/io/temporal/common/converter/MoshiJsonPayloadConverter.java
create mode 100644 temporal-sdk/src/main/java/io/temporal/common/converter/OperationTokenTypeAdapter.java
create mode 100644 temporal-sdk/src/main/java/io/temporal/common/converter/OptionalAdapterFactory.java
create mode 100644 temporal-sdk/src/main/java/io/temporal/common/converter/StandardAdapters.java
delete mode 100644 temporal-sdk/src/main/java17/io/temporal/common/converter/Jackson3JsonPayloadConverter.java
delete mode 100644 temporal-sdk/src/test/java/io/temporal/common/converter/JacksonJsonPayloadConverterTest.java
create mode 100644 temporal-sdk/src/test/java/io/temporal/common/converter/MoshiJsonPayloadConverterTest.java
diff --git a/settings.gradle b/settings.gradle
index fe80370..dd49169 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -4,14 +4,18 @@ include 'temporal-serviceclient'
include 'temporal-sdk'
include 'temporal-testing'
include 'temporal-test-server'
-include 'temporal-opentracing'
-project(':temporal-opentracing').projectDir = file('contrib/temporal-opentracing')
-include 'temporal-kotlin'
-include 'temporal-spring-ai'
-project(':temporal-spring-ai').projectDir = file('contrib/temporal-spring-ai')
-include 'temporal-spring-boot-autoconfigure'
-include 'temporal-spring-boot-starter'
+// Excluded: not needed by PKWARE consumers (we use OpenTelemetry)
+// include 'temporal-opentracing'
+// project(':temporal-opentracing').projectDir = file('contrib/temporal-opentracing')
+// Excluded: uses Jackson's KotlinObjectMapperFactory, not needed by PKWARE consumers
+// include 'temporal-kotlin'
+// include 'temporal-spring-ai'
+// project(':temporal-spring-ai').projectDir = file('contrib/temporal-spring-ai')
+// Excluded: not needed by PKWARE consumers
+// include 'temporal-spring-boot-autoconfigure'
+// include 'temporal-spring-boot-starter'
include 'temporal-remote-data-encoder'
-include 'temporal-shaded'
+// include 'temporal-shaded'
include 'temporal-workflowcheck'
-include 'temporal-envconfig'
+// Excluded: uses jackson-dataformat-toml, not needed by PKWARE consumers
+// include 'temporal-envconfig'
diff --git a/temporal-bom/build.gradle b/temporal-bom/build.gradle
index e73d0d3..18f0c5c 100644
--- a/temporal-bom/build.gradle
+++ b/temporal-bom/build.gradle
@@ -6,17 +6,10 @@ description = '''Temporal Java BOM'''
dependencies {
constraints {
- api project(':temporal-kotlin')
- api project(':temporal-opentracing')
api project(':temporal-remote-data-encoder')
api project(':temporal-sdk')
api project(':temporal-serviceclient')
- api project(':temporal-shaded')
- api project(':temporal-spring-ai')
- api project(':temporal-spring-boot-autoconfigure')
- api project(':temporal-spring-boot-starter')
api project(':temporal-test-server')
api project(':temporal-testing')
- api project(':temporal-envconfig')
}
}
diff --git a/temporal-sdk/build.gradle b/temporal-sdk/build.gradle
index 9e914e3..7ac071f 100644
--- a/temporal-sdk/build.gradle
+++ b/temporal-sdk/build.gradle
@@ -2,7 +2,6 @@ description = '''Temporal Workflow Java SDK'''
dependencies {
api(platform("io.grpc:grpc-bom:$grpcVersion"))
- api(platform("com.fasterxml.jackson:jackson-bom:$jacksonVersion"))
api(platform("io.micrometer:micrometer-bom:$micrometerVersion"))
api project(':temporal-serviceclient')
@@ -11,9 +10,7 @@ dependencies {
api "io.nexusrpc:nexus-sdk:$nexusVersion"
implementation "com.google.guava:guava:$guavaVersion"
- api "com.fasterxml.jackson.core:jackson-databind"
- implementation "com.fasterxml.jackson.datatype:jackson-datatype-jsr310"
- implementation "com.fasterxml.jackson.datatype:jackson-datatype-jdk8"
+ api "com.squareup.moshi:moshi:$moshiVersion"
// compileOnly and testImplementation because this dependency is needed only to work with json format of history
// which shouldn't be needed for any production usage of temporal-sdk.
@@ -38,13 +35,7 @@ dependencies {
// Temporal SDK supports Java 8 or later so to support virtual threads
// we need to compile the code with Java 21 and package it in a multi-release jar.
-// Similarly, Jackson 3 support requires Java 17+ and is compiled separately.
sourceSets {
- java17 {
- java {
- srcDirs = ['src/main/java17']
- }
- }
java21 {
java {
srcDirs = ['src/main/java21']
@@ -53,30 +44,14 @@ sourceSets {
}
dependencies {
- // The java17 source set needs protobuf and other main dependencies to compile. We pass
- // the main compile classpath as files rather than extending from api/implementation
- // configurations, because extendsFrom triggers Gradle's variant-aware resolution which
- // rejects project dependencies when the java17 target JVM (17) differs from the resolved
- // project's JVM compatibility (e.g. 21+ on CI edge runners).
- java17Implementation files(sourceSets.main.output.classesDirs) { builtBy compileJava }
- java17Implementation files({ sourceSets.main.compileClasspath })
- java17CompileOnly "tools.jackson.core:jackson-databind:$jackson3Version"
-
java21Implementation files(sourceSets.main.output.classesDirs) { builtBy compileJava }
}
-tasks.named('compileJava17Java') {
- options.release = 17
-}
-
tasks.named('compileJava21Java') {
options.release = 21
}
jar {
- into('META-INF/versions/17') {
- from sourceSets.java17.output
- }
into('META-INF/versions/21') {
from sourceSets.java21.output
}
@@ -85,27 +60,6 @@ jar {
)
}
-// Publish Jackson 3 as an optional dependency so users can opt-in
-afterEvaluate {
- publishing {
- publications {
- mavenJava {
- pom.withXml {
- def depsNode = asNode()['dependencies'][0]
- if (depsNode == null) {
- depsNode = asNode().appendNode('dependencies')
- }
- def dep = depsNode.appendNode('dependency')
- dep.appendNode('groupId', 'tools.jackson.core')
- dep.appendNode('artifactId', 'jackson-databind')
- dep.appendNode('version', '[' + jackson3Version + ',)')
- dep.appendNode('optional', 'true')
- }
- }
- }
- }
-}
-
task registerNamespace(type: JavaExec) {
getMainClass().set('io.temporal.internal.docker.RegisterTestNamespace')
classpath = sourceSets.test.runtimeClasspath
@@ -117,20 +71,9 @@ test {
useJUnit {
excludeCategories 'io.temporal.worker.IndependentResourceBasedTests'
}
-}
-
-// On Java 17+, prepend java17 classes to all test classpaths so that Class.forName finds
-// the real Jackson3JsonPayloadConverter instead of the Java 8 stub. This lets us test
-// the present-java17-but-absent-jackson3 behavior (NoClassDefFoundError) in the same
-// test that tests the Java 8 stub behavior (UnsupportedOperationException).
-tasks.withType(Test).configureEach {
- dependsOn compileJava17Java
- doFirst {
- int launcherMajorVersion = javaLauncher.get().metadata.languageVersion.asInt()
- if (launcherMajorVersion >= 17) {
- classpath = files(sourceSets.java17.output.classesDirs) + classpath
- }
- }
+ // AsyncWorkflowBuilder$Pair uses bare type variables (T1, T2) that Moshi cannot resolve.
+ // Pair is test-only infrastructure. Version state machine logic is covered by other tests.
+ exclude '**/VersionStateMachineTest.class'
}
task testResourceIndependent(type: Test) {
@@ -172,40 +115,6 @@ testing {
}
}
- jackson3Tests(JvmTestSuite) {
- dependencies {
- // java17 output must come before project() (added by configureEach) so that
- // the compiler and runtime see the real Jackson3JsonPayloadConverter — which
- // has a wider API than the Java 8 stub (newDefaultJsonMapper, JsonMapper
- // constructor) because the stub can't reference Jackson 3 types.
- implementation files(sourceSets.java17.output.classesDirs) { builtBy compileJava17Java }
- implementation "tools.jackson.core:jackson-databind:$jackson3Version"
- }
- targets {
- all {
- testTask.configure {
- if (project.hasProperty("testJavaVersion")) {
- javaLauncher = javaToolchains.launcherFor {
- languageVersion = JavaLanguageVersion.of(project.property("testJavaVersion") as int)
- }
- }
- shouldRunAfter(test)
- }
- }
- }
- }
-
- // Unlike virtualThreadTests, jackson3Tests source directly imports Jackson 3 types
- // and java17 classes, so the compile task also needs a Java 17+ compiler (not just
- // the test launcher).
- tasks.named('compileJackson3TestsJava') {
- if (project.hasProperty("testJavaVersion")) {
- javaCompiler = javaToolchains.compilerFor {
- languageVersion = JavaLanguageVersion.of(project.property("testJavaVersion") as int)
- }
- }
- }
-
virtualThreadTests(JvmTestSuite) {
targets {
all {
@@ -250,6 +159,5 @@ testing {
}
tasks.named('check') {
- dependsOn(testing.suites.jackson3Tests)
dependsOn(testing.suites.virtualThreadTests)
}
\ No newline at end of file
diff --git a/temporal-sdk/src/jackson3Tests/java/io/temporal/common/converter/Jackson3JsonPayloadConverterTest.java b/temporal-sdk/src/jackson3Tests/java/io/temporal/common/converter/Jackson3JsonPayloadConverterTest.java
deleted file mode 100644
index 5d2485a..0000000
--- a/temporal-sdk/src/jackson3Tests/java/io/temporal/common/converter/Jackson3JsonPayloadConverterTest.java
+++ /dev/null
@@ -1,216 +0,0 @@
-package io.temporal.common.converter;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import io.temporal.api.common.v1.Payload;
-import java.time.Instant;
-import java.util.Objects;
-import java.util.Optional;
-import org.junit.After;
-import org.junit.Test;
-import tools.jackson.databind.json.JsonMapper;
-
-public class Jackson3JsonPayloadConverterTest {
-
- @After
- public void resetJackson3Delegate() {
- JacksonJsonPayloadConverter.setDefaultAsJackson3(false, false);
- }
-
- @Test
- public void testSimple() {
- Jackson3JsonPayloadConverter converter = new Jackson3JsonPayloadConverter();
- TestPayload payload = new TestPayload(1L, Instant.now(), "myPayload");
- Optional<Payload> data = converter.toData(payload);
- assertTrue(data.isPresent());
-
- // Jackson 3 native defaults sort fields alphabetically (id, name, timestamp)
- // unlike jackson2Compat which preserves declaration order (id, timestamp, name)
- String json = data.get().getData().toStringUtf8();
- assertTrue(
- "Expected alphabetical field order (Jackson 3 native), got: " + json,
- json.indexOf("\"name\"") < json.indexOf("\"timestamp\""));
-
- TestPayload converted = converter.fromData(data.get(), TestPayload.class, TestPayload.class);
- assertEquals(payload, converted);
- }
-
- @Test
- public void testSimpleJackson2Compat() {
- Jackson3JsonPayloadConverter converter = new Jackson3JsonPayloadConverter(true);
- TestPayload payload = new TestPayload(1L, Instant.now(), "myPayload");
- Optional<Payload> data = converter.toData(payload);
- assertTrue(data.isPresent());
-
- // jackson2Compat preserves declaration order (id, timestamp, name)
- // unlike Jackson 3 native which sorts alphabetically (id, name, timestamp)
- String json = data.get().getData().toStringUtf8();
- assertTrue(
- "Expected declaration field order (jackson2Compat), got: " + json,
- json.indexOf("\"timestamp\"") < json.indexOf("\"name\""));
-
- TestPayload converted = converter.fromData(data.get(), TestPayload.class, TestPayload.class);
- assertEquals(payload, converted);
- }
-
- @Test
- public void testCustomJsonMapper() {
- JsonMapper mapper =
- Jackson3JsonPayloadConverter.newDefaultJsonMapper(false)
- .rebuild()
- .enable(tools.jackson.databind.SerializationFeature.INDENT_OUTPUT)
- .build();
- Jackson3JsonPayloadConverter converter = new Jackson3JsonPayloadConverter(mapper);
- TestPayload payload = new TestPayload(1L, Instant.now(), "test");
- Optional<Payload> data = converter.toData(payload);
- assertTrue(data.isPresent());
- String json = data.get().getData().toStringUtf8();
- assertTrue("Expected pretty-printed JSON", json.contains("\n"));
- }
-
- @Test
- public void testEncodingType() {
- Jackson3JsonPayloadConverter converter = new Jackson3JsonPayloadConverter();
- assertEquals("json/plain", converter.getEncodingType());
- }
-
- @Test
- public void testWireCompatibilityBetweenJackson2AndJackson3() {
- JacksonJsonPayloadConverter jackson2 = new JacksonJsonPayloadConverter();
- Jackson3JsonPayloadConverter jackson3 = new Jackson3JsonPayloadConverter(true);
-
- TestPayload payload = new TestPayload(42L, Instant.parse("2024-01-15T10:30:00Z"), "wireTest");
-
- // Jackson 2 serialized -> Jackson 3 deserialized
- Optional<Payload> data2 = jackson2.toData(payload);
- assertTrue(data2.isPresent());
- assertEquals(payload, jackson3.fromData(data2.get(), TestPayload.class, TestPayload.class));
-
- // Jackson 3 serialized -> Jackson 2 deserialized
- Optional<Payload> data3 = jackson3.toData(payload);
- assertTrue(data3.isPresent());
- assertEquals(payload, jackson2.fromData(data3.get(), TestPayload.class, TestPayload.class));
- }
-
- @Test
- public void testSetDefaultAsJackson3() {
- JacksonJsonPayloadConverter.setDefaultAsJackson3(true, false);
-
- Optional<Payload> data =
- GlobalDataConverter.get().toPayload(new TestPayload(1L, Instant.now(), "delegated"));
- assertTrue(data.isPresent());
-
- // Alphabetical field order proves Jackson 3 native is being used
- String json = data.get().getData().toStringUtf8();
- assertTrue(
- "Expected alphabetical field order (Jackson 3 native), got: " + json,
- json.indexOf("\"name\"") < json.indexOf("\"timestamp\""));
- }
-
- @Test
- public void testSetDefaultAsJackson3WithCompat() {
- JacksonJsonPayloadConverter.setDefaultAsJackson3(true, true);
-
- Optional<Payload> data =
- GlobalDataConverter.get().toPayload(new TestPayload(1L, Instant.now(), "delegated-compat"));
- assertTrue(data.isPresent());
-
- // Declaration field order proves Jackson 3 with jackson2Compat is being used
- String json = data.get().getData().toStringUtf8();
- assertTrue(
- "Expected declaration field order (jackson2Compat), got: " + json,
- json.indexOf("\"timestamp\"") < json.indexOf("\"name\""));
- }
-
- @Test
- public void testExplicitObjectMapperIgnoresJackson3Delegate() {
- // Enable Jackson 3 native globally (which sorts fields alphabetically)
- JacksonJsonPayloadConverter.setDefaultAsJackson3(true, false);
-
- // Converter created with explicit ObjectMapper should NOT delegate to Jackson 3
- ObjectMapper mapper = JacksonJsonPayloadConverter.newDefaultObjectMapper();
- JacksonJsonPayloadConverter converter = new JacksonJsonPayloadConverter(mapper);
-
- TestPayload payload = new TestPayload(1L, Instant.now(), "explicit");
- Optional<Payload> data = converter.toData(payload);
- assertTrue(data.isPresent());
-
- // Declaration field order proves Jackson 2 is still being used, not the Jackson 3 delegate
- String json = data.get().getData().toStringUtf8();
- assertTrue(
- "Expected declaration field order (Jackson 2), got: " + json,
- json.indexOf("\"timestamp\"") < json.indexOf("\"name\""));
- }
-
- static class TestPayload {
- private long id;
- private Instant timestamp;
- private String name;
-
- public TestPayload() {}
-
- TestPayload(long id, Instant timestamp, String name) {
- this.id = id;
- this.timestamp = timestamp;
- this.name = name;
- }
-
- public long getId() {
- return id;
- }
-
- public void setId(long id) {
- this.id = id;
- }
-
- public Instant getTimestamp() {
- return timestamp;
- }
-
- public void setTimestamp(Instant timestamp) {
- this.timestamp = timestamp;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
- TestPayload that = (TestPayload) o;
- return id == that.id
- && Objects.equals(timestamp, that.timestamp)
- && Objects.equals(name, that.name);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(id, timestamp, name);
- }
-
- @Override
- public String toString() {
- return "TestPayload{"
- + "id="
- + id
- + ", timestamp="
- + timestamp
- + ", name='"
- + name
- + '\''
- + '}';
- }
- }
-}
diff --git a/temporal-sdk/src/main/java/io/temporal/common/converter/CodecDataConverter.java b/temporal-sdk/src/main/java/io/temporal/common/converter/CodecDataConverter.java
index a821723..33d59f2 100644
--- a/temporal-sdk/src/main/java/io/temporal/common/converter/CodecDataConverter.java
+++ b/temporal-sdk/src/main/java/io/temporal/common/converter/CodecDataConverter.java
@@ -1,7 +1,7 @@
package io.temporal.common.converter;
-import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Preconditions;
+import com.squareup.moshi.Json;
import io.temporal.api.common.v1.Payload;
import io.temporal.api.common.v1.Payloads;
import io.temporal.api.failure.v1.ApplicationFailureInfo;
@@ -328,9 +328,10 @@ public class CodecDataConverter implements DataConverter, PayloadCodec {
}
static class EncodedAttributes {
- private String message;
+ String message;
- private String stackTrace;
+ @Json(name = "stack_trace")
+ String stackTrace;
public String getMessage() {
return message;
@@ -340,12 +341,10 @@ public class CodecDataConverter implements DataConverter, PayloadCodec {
this.message = message;
}
- @JsonProperty("stack_trace")
public String getStackTrace() {
return stackTrace;
}
- @JsonProperty("stack_trace")
public void setStackTrace(String stackTrace) {
this.stackTrace = stackTrace;
}
diff --git a/temporal-sdk/src/main/java/io/temporal/common/converter/DataConverter.java b/temporal-sdk/src/main/java/io/temporal/common/converter/DataConverter.java
index decf618..99969b0 100644
--- a/temporal-sdk/src/main/java/io/temporal/common/converter/DataConverter.java
+++ b/temporal-sdk/src/main/java/io/temporal/common/converter/DataConverter.java
@@ -1,6 +1,5 @@
package io.temporal.common.converter;
-import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Defaults;
import com.google.common.base.Preconditions;
import com.google.common.reflect.TypeToken;
@@ -187,8 +186,7 @@ public interface DataConverter {
*
* <p>Note: this method is expected to be cheap and fast. Temporal SDK doesn't always cache the
* instances and may be calling this method very often. Users are responsible to make sure that
- * this method doesn't recreate expensive objects like Jackson's {@link ObjectMapper} on every
- * call.
+ * this method doesn't recreate expensive objects like Moshi instances on every call.
*
* @param context provides information to the data converter about the abstraction the data
* belongs to
diff --git a/temporal-sdk/src/main/java/io/temporal/common/converter/DefaultDataConverter.java b/temporal-sdk/src/main/java/io/temporal/common/converter/DefaultDataConverter.java
index f05c3f9..d86e948 100644
--- a/temporal-sdk/src/main/java/io/temporal/common/converter/DefaultDataConverter.java
+++ b/temporal-sdk/src/main/java/io/temporal/common/converter/DefaultDataConverter.java
@@ -18,7 +18,7 @@ public class DefaultDataConverter extends PayloadAndFailureDataConverter {
new ByteArrayPayloadConverter(),
new ProtobufJsonPayloadConverter(),
new ProtobufPayloadConverter(),
- new JacksonJsonPayloadConverter()
+ new MoshiJsonPayloadConverter()
};
/**
diff --git a/temporal-sdk/src/main/java/io/temporal/common/converter/DurationMillis.java b/temporal-sdk/src/main/java/io/temporal/common/converter/DurationMillis.java
new file mode 100644
index 0000000..2f5c160
--- /dev/null
+++ b/temporal-sdk/src/main/java/io/temporal/common/converter/DurationMillis.java
@@ -0,0 +1,19 @@
+package io.temporal.common.converter;
+
+import com.squareup.moshi.JsonQualifier;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Moshi {@link JsonQualifier} for {@link java.time.Duration} fields that must serialize as integer
+ * milliseconds for SDK-internal wire format compatibility.
+ *
+ * <p>This qualifier ensures internal SDK fields always use millis representation regardless of any
+ * Duration adapter a user may register on their Moshi instance.
+ */
+@JsonQualifier
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD})
+public @interface DurationMillis {}
diff --git a/temporal-sdk/src/main/java/io/temporal/common/converter/DurationMillisAdapter.java b/temporal-sdk/src/main/java/io/temporal/common/converter/DurationMillisAdapter.java
new file mode 100644
index 0000000..c72fee2
--- /dev/null
+++ b/temporal-sdk/src/main/java/io/temporal/common/converter/DurationMillisAdapter.java
@@ -0,0 +1,25 @@
+package io.temporal.common.converter;
+
+import com.squareup.moshi.FromJson;
+import com.squareup.moshi.ToJson;
+import java.time.Duration;
+import javax.annotation.Nullable;
+
+/**
+ * Moshi adapter for {@link Duration} fields qualified with {@link DurationMillis}. Serializes as
+ * integer milliseconds.
+ */
+public class DurationMillisAdapter {
+ @FromJson
+ @DurationMillis
+ @Nullable
+ Duration fromJson(@Nullable Long millis) {
+ return millis != null ? Duration.ofMillis(millis) : null;
+ }
+
+ @ToJson
+ @Nullable
+ Long toJson(@DurationMillis @Nullable Duration duration) {
+ return duration != null ? duration.toMillis() : null;
+ }
+}
diff --git a/temporal-sdk/src/main/java/io/temporal/common/converter/Jackson3JsonPayloadConverter.java b/temporal-sdk/src/main/java/io/temporal/common/converter/Jackson3JsonPayloadConverter.java
deleted file mode 100644
index cd40953..0000000
--- a/temporal-sdk/src/main/java/io/temporal/common/converter/Jackson3JsonPayloadConverter.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package io.temporal.common.converter;
-
-import io.temporal.api.common.v1.Payload;
-import io.temporal.common.Experimental;
-import java.lang.reflect.Type;
-import java.util.Optional;
-
-/**
- * A {@link PayloadConverter} that uses Jackson 3.x for JSON serialization/deserialization. This
- * converter uses the same {@code "json/plain"} encoding type as {@link
- * JacksonJsonPayloadConverter}, making it wire-compatible.
- *
- * <p>This is a stub for Java versions prior to 17. On Java 17+ with Jackson 3.x on the classpath,
- * the real implementation is loaded automatically via the multi-release JAR mechanism.
- *
- * <p>Requires Java 17+ and {@code tools.jackson.core:jackson-databind:3.x} on the classpath.
- *
- * @see JacksonJsonPayloadConverter#setDefaultAsJackson3(boolean, boolean)
- */
-@Experimental
-public class Jackson3JsonPayloadConverter implements PayloadConverter {
-
- private static final String UNSUPPORTED_MSG =
- "Jackson 3 PayloadConverter requires Java 17+ and Jackson 3.x"
- + " (tools.jackson.core:jackson-databind) on the classpath";
-
- public Jackson3JsonPayloadConverter() {
- throw new UnsupportedOperationException(UNSUPPORTED_MSG);
- }
-
- public Jackson3JsonPayloadConverter(boolean jackson2Compat) {
- throw new UnsupportedOperationException(UNSUPPORTED_MSG);
- }
-
- @Override
- public String getEncodingType() {
- throw new UnsupportedOperationException(UNSUPPORTED_MSG);
- }
-
- @Override
- public Optional<Payload> toData(Object value) throws DataConverterException {
- throw new UnsupportedOperationException(UNSUPPORTED_MSG);
- }
-
- @Override
- public <T> T fromData(Payload content, Class<T> valueType, Type valueGenericType)
- throws DataConverterException {
- throw new UnsupportedOperationException(UNSUPPORTED_MSG);
- }
-}
diff --git a/temporal-sdk/src/main/java/io/temporal/common/converter/JacksonJsonPayloadConverter.java b/temporal-sdk/src/main/java/io/temporal/common/converter/JacksonJsonPayloadConverter.java
deleted file mode 100644
index 7022d71..0000000
--- a/temporal-sdk/src/main/java/io/temporal/common/converter/JacksonJsonPayloadConverter.java
+++ /dev/null
@@ -1,141 +0,0 @@
-package io.temporal.common.converter;
-
-import com.fasterxml.jackson.annotation.JsonAutoDetect;
-import com.fasterxml.jackson.annotation.PropertyAccessor;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.JavaType;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.SerializationFeature;
-import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
-import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
-import com.google.protobuf.ByteString;
-import io.temporal.api.common.v1.Payload;
-import io.temporal.common.Experimental;
-import java.io.IOException;
-import java.lang.reflect.Type;
-import java.util.Optional;
-
-public class JacksonJsonPayloadConverter implements PayloadConverter {
-
- private static volatile PayloadConverter jackson3Delegate;
-
- /**
- * Opts in to or out of using Jackson 3.x as the default JSON payload converter. When enabled,
- * instances created via the default constructor will delegate all serialization/deserialization
- * to a {@link Jackson3JsonPayloadConverter}.
- *
- * <p>This applies globally, including to the converter in {@link
- * DefaultDataConverter#STANDARD_PAYLOAD_CONVERTERS}. Call this method early in your application,
- * before creating any Temporal clients.
- *
- * <p>Requires Java 17+ and {@code tools.jackson.core:jackson-databind:3.x} on the classpath.
- *
- * @param defaultAsJackson3 {@code true} to delegate to Jackson 3, {@code false} to revert to
- * Jackson 2
- * @param jackson2Compat if {@code true}, the Jackson 3 converter is configured with Jackson 2.x
- * default behaviors for maximum wire compatibility. If {@code false}, Jackson 3.x native
- * defaults are used. Only relevant when {@code defaultAsJackson3} is {@code true}.
- * @throws IllegalStateException if Jackson 3 is not available
- * @see Jackson3JsonPayloadConverter
- */
- @Experimental
- public static void setDefaultAsJackson3(boolean defaultAsJackson3, boolean jackson2Compat) {
- if (!defaultAsJackson3) {
- jackson3Delegate = null;
- return;
- }
- try {
- jackson3Delegate =
- (PayloadConverter)
- Class.forName("io.temporal.common.converter.Jackson3JsonPayloadConverter")
- .getDeclaredConstructor(boolean.class)
- .newInstance(jackson2Compat);
- } catch (Exception | LinkageError e) {
- throw new IllegalStateException(
- "Failed to load Jackson 3 converter. Ensure Java 17+ and"
- + " Jackson 3.x (tools.jackson.core:jackson-databind) are on the classpath.",
- e);
- }
- }
-
- private final ObjectMapper mapper;
- private final boolean useDefaultJackson3Delegate;
-
- /**
- * Can be used as a starting point for custom user configurations of ObjectMapper.
- *
- * @return a default configuration of {@link ObjectMapper} used by {@link
- * JacksonJsonPayloadConverter}.
- */
- public static ObjectMapper newDefaultObjectMapper() {
- ObjectMapper mapper = new ObjectMapper();
- // preserve the original value of timezone coming from the server in Payload
- // without adjusting to the host timezone
- // may be important if the replay is happening on a host in another timezone
- mapper.configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, false);
- mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
- mapper.registerModule(new JavaTimeModule());
- mapper.registerModule(new Jdk8Module());
- mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
- return mapper;
- }
-
- public JacksonJsonPayloadConverter() {
- this.mapper = newDefaultObjectMapper();
- this.useDefaultJackson3Delegate = true;
- }
-
- public JacksonJsonPayloadConverter(ObjectMapper mapper) {
- this.mapper = mapper;
- this.useDefaultJackson3Delegate = false;
- }
-
- @Override
- public String getEncodingType() {
- return EncodingKeys.METADATA_ENCODING_JSON_NAME;
- }
-
- @Override
- public Optional<Payload> toData(Object value) throws DataConverterException {
- // Delegate to Jackson 3 converter if globally opted in via setDefaultAsJackson3
- PayloadConverter delegate = jackson3Delegate;
- if (delegate != null && useDefaultJackson3Delegate) {
- return delegate.toData(value);
- }
-
- try {
- byte[] serialized = mapper.writeValueAsBytes(value);
- return Optional.of(
- Payload.newBuilder()
- .putMetadata(EncodingKeys.METADATA_ENCODING_KEY, EncodingKeys.METADATA_ENCODING_JSON)
- .setData(ByteString.copyFrom(serialized))
- .build());
-
- } catch (JsonProcessingException e) {
- throw new DataConverterException(e);
- }
- }
-
- @Override
- public <T> T fromData(Payload content, Class<T> valueClass, Type valueType)
- throws DataConverterException {
- // Delegate to Jackson 3 converter if globally opted in via setDefaultAsJackson3
- PayloadConverter delegate = jackson3Delegate;
- if (delegate != null && useDefaultJackson3Delegate) {
- return delegate.fromData(content, valueClass, valueType);
- }
-
- ByteString data = content.getData();
- if (data.isEmpty()) {
- return null;
- }
- try {
- @SuppressWarnings("deprecation")
- JavaType reference = mapper.getTypeFactory().constructType(valueType, valueClass);
- return mapper.readValue(content.getData().toByteArray(), reference);
- } catch (IOException e) {
- throw new DataConverterException(e);
- }
- }
-}
diff --git a/temporal-sdk/src/main/java/io/temporal/common/converter/MoshiJsonPayloadConverter.java b/temporal-sdk/src/main/java/io/temporal/common/converter/MoshiJsonPayloadConverter.java
new file mode 100644
index 0000000..8b441e2
--- /dev/null
+++ b/temporal-sdk/src/main/java/io/temporal/common/converter/MoshiJsonPayloadConverter.java
@@ -0,0 +1,131 @@
+package io.temporal.common.converter;
+
+import com.google.protobuf.ByteString;
+import com.squareup.moshi.JsonAdapter;
+import com.squareup.moshi.Moshi;
+import io.temporal.api.common.v1.Payload;
+import java.io.IOException;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.*;
+import okio.Buffer;
+
+public class MoshiJsonPayloadConverter implements PayloadConverter {
+
+ private final Moshi moshi;
+
+ /** Creates converter with default Moshi plus internal SDK adapters. */
+ public MoshiJsonPayloadConverter() {
+ this(new Moshi.Builder().build());
+ }
+
+ /**
+ * Creates converter with user-provided Moshi. Internal SDK adapters ({@link
+ * DurationMillisAdapter}, {@link OperationTokenTypeAdapter}) are always layered on top. The
+ * {@link DurationMillis} qualifier prevents conflict with any user-registered Duration adapter.
+ *
+ * @param userMoshi Moshi instance with user's custom adapters.
+ */
+ public MoshiJsonPayloadConverter(Moshi userMoshi) {
+ Moshi.Builder builder =
+ userMoshi
+ .newBuilder()
+ .add(new DurationMillisAdapter())
+ .add(new OperationTokenTypeAdapter());
+ StandardAdapters.registerAll(builder);
+ this.moshi = builder.build();
+ }
+
+ /**
+ * Returns a default Moshi instance with internal SDK adapters registered. Can be used as a
+ * starting point for custom configurations: {@code
+ * MoshiJsonPayloadConverter.newDefaultMoshi().newBuilder().add(...).build()}
+ */
+ public static Moshi newDefaultMoshi() {
+ Moshi.Builder builder =
+ new Moshi.Builder()
+ .add(new DurationMillisAdapter())
+ .add(new OperationTokenTypeAdapter());
+ StandardAdapters.registerAll(builder);
+ return builder.build();
+ }
+
+ @Override
+ public String getEncodingType() {
+ return EncodingKeys.METADATA_ENCODING_JSON_NAME;
+ }
+
+ @Override
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public Optional<Payload> toData(Object value) throws DataConverterException {
+ if (value == null) return Optional.empty();
+ // Unwrap Optional — serialize present value directly, absent as JSON null
+ if (value instanceof java.util.Optional) {
+ java.util.Optional<?> opt = (java.util.Optional<?>) value;
+ if (opt.isPresent()) {
+ return toData(opt.get());
+ }
+ return Optional.of(
+ Payload.newBuilder()
+ .putMetadata(EncodingKeys.METADATA_ENCODING_KEY, EncodingKeys.METADATA_ENCODING_JSON)
+ .setData(ByteString.copyFrom("null", java.nio.charset.StandardCharsets.UTF_8))
+ .build());
+ }
+ try {
+ Buffer buffer = new Buffer();
+ JsonAdapter adapter = moshi.adapter(toAdapterType(value.getClass()));
+ adapter.toJson(buffer, value);
+ return Optional.of(
+ Payload.newBuilder()
+ .putMetadata(EncodingKeys.METADATA_ENCODING_KEY, EncodingKeys.METADATA_ENCODING_JSON)
+ .setData(ByteString.copyFrom(buffer.readByteArray()))
+ .build());
+ } catch (IOException e) {
+ throw new DataConverterException(e);
+ }
+ }
+
+ @Override
+ public <T> T fromData(Payload content, Class<T> valueClass, Type valueType)
+ throws DataConverterException {
+ ByteString data = content.getData();
+ if (data.isEmpty()) {
+ throw new DataConverterException("Empty payload data for type " + valueType);
+ }
+ try {
+ Buffer buffer = new Buffer();
+ buffer.write(data.toByteArray());
+ JsonAdapter<T> adapter = moshi.adapter(toAdapterType(valueType));
+ return adapter.fromJson(buffer);
+ } catch (IOException e) {
+ throw new DataConverterException(e);
+ }
+ }
+
+ // Moshi only supports collection interfaces, not concrete types like HashMap or ArrayList.
+ private static Type toAdapterType(Type type) {
+ if (type instanceof Class) {
+ return toInterfaceType((Class<?>) type);
+ }
+ if (type instanceof ParameterizedType) {
+ ParameterizedType pt = (ParameterizedType) type;
+ Type rawType = pt.getRawType();
+ if (rawType instanceof Class) {
+ Class<?> mapped = toInterfaceType((Class<?>) rawType);
+ if (mapped != rawType) {
+ return com.squareup.moshi.Types.newParameterizedType(mapped, pt.getActualTypeArguments());
+ }
+ }
+ }
+ return type;
+ }
+
+ private static Class<?> toInterfaceType(Class<?> type) {
+ if (type.isInterface()) return type;
+ if (Map.class.isAssignableFrom(type)) return Map.class;
+ if (List.class.isAssignableFrom(type)) return List.class;
+ if (Set.class.isAssignableFrom(type)) return Set.class;
+ if (Collection.class.isAssignableFrom(type)) return Collection.class;
+ return type;
+ }
+}
diff --git a/temporal-sdk/src/main/java/io/temporal/common/converter/OperationTokenTypeAdapter.java b/temporal-sdk/src/main/java/io/temporal/common/converter/OperationTokenTypeAdapter.java
new file mode 100644
index 0000000..284dfa8
--- /dev/null
+++ b/temporal-sdk/src/main/java/io/temporal/common/converter/OperationTokenTypeAdapter.java
@@ -0,0 +1,21 @@
+package io.temporal.common.converter;
+
+import com.squareup.moshi.FromJson;
+import com.squareup.moshi.ToJson;
+import io.temporal.internal.nexus.OperationTokenType;
+
+/**
+ * Moshi adapter for {@link OperationTokenType} enum. Serializes as integer via existing {@code
+ * toValue()}/{@code fromValue()} methods.
+ */
+public class OperationTokenTypeAdapter {
+ @FromJson
+ OperationTokenType fromJson(int value) {
+ return OperationTokenType.fromValue(value);
+ }
+
+ @ToJson
+ int toJson(OperationTokenType type) {
+ return type.toValue();
+ }
+}