From fdbffeacc721880a669938722689752e13679c64 Mon Sep 17 00:00:00 2001 From: Marius Volkhart Date: Fri, 26 Jun 2026 06:46:07 -0400 Subject: [PATCH] chore(patches): remove Gson removal patch grpc-core declares Gson as an implementation dependency, so Gson is always on the runtime classpath regardless. The patch achieved nothing for classpath minimization and brought back GsonJsonPayloadConverter unnecessarily. Remaining patches renumbered 0002-0004. Co-Authored-By: Claude Sonnet 4.6 (1M context) --- patches/0002-Remove-GSON-dependency.patch | 284 ------------------ ...e-grpc-netty-shaded-with-grpc-netty.patch} | 0 ...ange-groupId-to-com.pkware.temporal.patch} | 0 ...h => 0004-Add-Wire-protobuf-support.patch} | 0 4 files changed, 284 deletions(-) delete mode 100644 patches/0002-Remove-GSON-dependency.patch rename patches/{0003-Replace-grpc-netty-shaded-with-grpc-netty.patch => 0002-Replace-grpc-netty-shaded-with-grpc-netty.patch} (100%) rename patches/{0004-Change-groupId-to-com.pkware.temporal.patch => 0003-Change-groupId-to-com.pkware.temporal.patch} (100%) rename patches/{0005-Add-Wire-protobuf-support.patch => 0004-Add-Wire-protobuf-support.patch} (100%) diff --git a/patches/0002-Remove-GSON-dependency.patch b/patches/0002-Remove-GSON-dependency.patch deleted file mode 100644 index cf14629..0000000 --- a/patches/0002-Remove-GSON-dependency.patch +++ /dev/null @@ -1,284 +0,0 @@ -From c92c4c63735c19badc6d9a0ad3e28b74947aa892 Mon Sep 17 00:00:00 2001 -From: Marius Volkhart -Date: Thu, 21 May 2026 14:41:44 -0400 -Subject: [PATCH] Remove GSON dependency - -Delete GsonJsonPayloadConverter. Replace GSON pretty-printing in -WorkflowExecutionHistory with protobuf JsonFormat.printer(). -Remove dead fixStackTrace method from WorkflowExecutionUtils. ---- - temporal-sdk/build.gradle | 1 - - .../converter/GsonJsonPayloadConverter.java | 85 ------------------- - .../common/WorkflowExecutionHistory.java | 38 ++++----- - .../common/WorkflowExecutionUtils.java | 19 ----- - .../common/WorkflowExecutionHistoryTest.java | 6 +- - .../java/io/temporal/workflow/MemoTest.java | 4 +- - 6 files changed, 25 insertions(+), 128 deletions(-) - delete mode 100644 temporal-sdk/src/main/java/io/temporal/common/converter/GsonJsonPayloadConverter.java - -diff --git a/temporal-sdk/build.gradle b/temporal-sdk/build.gradle -index 7ac071f..3e39f30 100644 ---- a/temporal-sdk/build.gradle -+++ b/temporal-sdk/build.gradle -@@ -5,7 +5,6 @@ dependencies { - api(platform("io.micrometer:micrometer-bom:$micrometerVersion")) - - api project(':temporal-serviceclient') -- api "com.google.code.gson:gson:$gsonVersion" - api "io.micrometer:micrometer-core" - api "io.nexusrpc:nexus-sdk:$nexusVersion" - -diff --git a/temporal-sdk/src/main/java/io/temporal/common/converter/GsonJsonPayloadConverter.java b/temporal-sdk/src/main/java/io/temporal/common/converter/GsonJsonPayloadConverter.java -deleted file mode 100644 -index c2d361b..0000000 ---- a/temporal-sdk/src/main/java/io/temporal/common/converter/GsonJsonPayloadConverter.java -+++ /dev/null -@@ -1,85 +0,0 @@ --package io.temporal.common.converter; -- --import com.google.gson.Gson; --import com.google.gson.GsonBuilder; --import com.google.protobuf.ByteString; --import io.temporal.api.common.v1.Payload; --import java.lang.reflect.Type; --import java.nio.charset.StandardCharsets; --import java.util.Optional; --import java.util.function.Function; -- --/** -- * Implements conversion through GSON JSON processor. To extend use {@link -- * #GsonJsonPayloadConverter(Function)} constructor. -- * -- * @author fateev -- */ --public final class GsonJsonPayloadConverter implements PayloadConverter { -- -- private static final PayloadConverter INSTANCE = new GsonJsonPayloadConverter(); -- -- private final Gson gson; -- -- public static PayloadConverter getInstance() { -- return INSTANCE; -- } -- -- public GsonJsonPayloadConverter() { -- this((b) -> b); -- } -- -- /** -- * Constructs an instance giving an ability to override {@link Gson} initialization. -- * -- * @param builderInterceptor function that intercepts {@link GsonBuilder} construction. -- */ -- public GsonJsonPayloadConverter(Function builderInterceptor) { -- GsonBuilder gsonBuilder = new GsonBuilder().serializeNulls(); -- GsonBuilder intercepted = builderInterceptor.apply(gsonBuilder); -- gson = intercepted.create(); -- } -- -- @Override -- public String getEncodingType() { -- return EncodingKeys.METADATA_ENCODING_JSON_NAME; -- } -- -- /** -- * Return empty if value is null. Exception stack traces are converted to a single string stack -- * trace to save space and make them more readable. -- */ -- @Override -- public Optional toData(Object value) throws DataConverterException { -- try { -- String json = gson.toJson(value); -- return Optional.of( -- Payload.newBuilder() -- .putMetadata(EncodingKeys.METADATA_ENCODING_KEY, EncodingKeys.METADATA_ENCODING_JSON) -- .setData(ByteString.copyFrom(json, StandardCharsets.UTF_8)) -- .build()); -- } catch (DataConverterException e) { -- throw e; -- } catch (Throwable e) { -- throw new DataConverterException(e); -- } -- } -- -- @Override -- public T fromData(Payload content, Class valueClass, Type valueType) -- throws DataConverterException { -- if (content == null) { -- return null; -- } -- ByteString data = content.getData(); -- if (data.isEmpty()) { -- return null; -- } -- try { -- String json = data.toString(StandardCharsets.UTF_8); -- return gson.fromJson(json, valueType); -- } catch (Exception e) { -- throw new DataConverterException(content, new Type[] {valueType}, e); -- } -- } --} -diff --git a/temporal-sdk/src/main/java/io/temporal/internal/common/WorkflowExecutionHistory.java b/temporal-sdk/src/main/java/io/temporal/internal/common/WorkflowExecutionHistory.java -index 3b4b7b2..9515701 100644 ---- a/temporal-sdk/src/main/java/io/temporal/internal/common/WorkflowExecutionHistory.java -+++ b/temporal-sdk/src/main/java/io/temporal/internal/common/WorkflowExecutionHistory.java -@@ -1,17 +1,15 @@ - package io.temporal.internal.common; - --import com.google.gson.Gson; --import com.google.gson.GsonBuilder; --import com.google.gson.JsonElement; --import com.google.gson.JsonParser; --import com.google.protobuf.InvalidProtocolBufferException; - import com.google.protobuf.util.JsonFormat; -+import com.squareup.moshi.JsonWriter; - import io.temporal.api.common.v1.WorkflowExecution; - import io.temporal.api.enums.v1.EventType; - import io.temporal.api.history.v1.History; - import io.temporal.api.history.v1.HistoryEvent; - import io.temporal.common.converter.DataConverterException; -+import java.io.IOException; - import java.util.List; -+import okio.Buffer; - - // This class by mistake leaked into a public interface and is used by users, so it can't be deleted - // right away. -@@ -24,12 +22,6 @@ import java.util.List; - @Deprecated - public class WorkflowExecutionHistory { - protected static final String DEFAULT_WORKFLOW_ID = "workflow_id_in_replay"; -- private static final Gson GSON_PRETTY_PRINTER = new GsonBuilder().setPrettyPrinting().create(); -- -- // we stay on using the old API that uses a JsonParser instance instead of static methods -- // to give users a larger range of supported version -- @SuppressWarnings("deprecation") -- private static final JsonParser GSON_PARSER = new JsonParser(); - - private final History history; - private final String workflowId; -@@ -89,23 +81,31 @@ public class WorkflowExecutionHistory { - public String toJson(boolean prettyPrint, boolean legacyFormat) { - JsonFormat.Printer printer = JsonFormat.printer(); - try { -- String protoJson = printer.print(history); -+ String protoJson = printer.omittingInsignificantWhitespace().print(history); - if (legacyFormat) { - protoJson = HistoryJsonUtils.protoJsonToHistoryFormatJson(protoJson); - } -- - if (prettyPrint) { -- @SuppressWarnings("deprecation") -- JsonElement je = GSON_PARSER.parse(protoJson); -- return GSON_PRETTY_PRINTER.toJson(je); -- } else { -- return protoJson; -+ protoJson = prettyPrintJson(protoJson); - } -- } catch (InvalidProtocolBufferException e) { -+ return protoJson; -+ } catch (IOException e) { - throw new DataConverterException(e); - } - } - -+ private static String prettyPrintJson(String compact) throws IOException { -+ com.squareup.moshi.Moshi moshi = new com.squareup.moshi.Moshi.Builder().build(); -+ com.squareup.moshi.JsonAdapter adapter = moshi.adapter(Object.class); -+ Object parsed = adapter.fromJson(compact); -+ Buffer sink = new Buffer(); -+ JsonWriter writer = JsonWriter.of(sink); -+ writer.setIndent(" "); -+ adapter.toJson(writer, parsed); -+ writer.close(); -+ return sink.readUtf8(); -+ } -+ - /** - * Returns workflow instance history in a human-readable format. - * -diff --git a/temporal-sdk/src/main/java/io/temporal/internal/common/WorkflowExecutionUtils.java b/temporal-sdk/src/main/java/io/temporal/internal/common/WorkflowExecutionUtils.java -index ee3c3d3..d7644f0 100644 ---- a/temporal-sdk/src/main/java/io/temporal/internal/common/WorkflowExecutionUtils.java -+++ b/temporal-sdk/src/main/java/io/temporal/internal/common/WorkflowExecutionUtils.java -@@ -1,7 +1,5 @@ - package io.temporal.internal.common; - --import com.google.gson.JsonElement; --import com.google.gson.JsonPrimitive; - import com.google.protobuf.MessageOrBuilder; - import com.google.protobuf.TextFormat; - import io.temporal.api.command.v1.Command; -@@ -23,7 +21,6 @@ import io.temporal.failure.TerminatedFailure; - import io.temporal.failure.TimeoutFailure; - import java.util.ArrayList; - import java.util.List; --import java.util.Map.Entry; - import java.util.Optional; - import javax.annotation.Nullable; - -@@ -258,22 +255,6 @@ public class WorkflowExecutionUtils { - return false; - } - -- private static void fixStackTrace(JsonElement json, String stackIndentation) { -- if (!json.isJsonObject()) { -- return; -- } -- for (Entry entry : json.getAsJsonObject().entrySet()) { -- if ("stackTrace".equals(entry.getKey())) { -- String value = entry.getValue().getAsString(); -- String replacement = "\n" + stackIndentation; -- String fixed = value.replaceAll("\\n", replacement); -- entry.setValue(new JsonPrimitive(fixed)); -- continue; -- } -- fixStackTrace(entry.getValue(), stackIndentation + INDENTATION); -- } -- } -- - /** Command event is an event that is created to mirror a command issued by a workflow task */ - public static boolean isCommandEvent(HistoryEvent event) { - EventType eventType = event.getEventType(); -diff --git a/temporal-sdk/src/test/java/io/temporal/internal/common/WorkflowExecutionHistoryTest.java b/temporal-sdk/src/test/java/io/temporal/internal/common/WorkflowExecutionHistoryTest.java -index 35caba9..ca54618 100644 ---- a/temporal-sdk/src/test/java/io/temporal/internal/common/WorkflowExecutionHistoryTest.java -+++ b/temporal-sdk/src/test/java/io/temporal/internal/common/WorkflowExecutionHistoryTest.java -@@ -70,8 +70,10 @@ public class WorkflowExecutionHistoryTest { - - WorkflowExecutionHistory history = WorkflowHistoryLoader.readHistoryFromResource(resourceName); - -- // Confirm serialized to old matches char-for-char -- assertEquals(originalSerializedJsonHistory, history.toJson(true, true)); -+ // Confirm serialized to old is structurally equivalent (formatting may differ) -+ WorkflowExecutionHistory roundTripped = -+ WorkflowExecutionHistory.fromJson(history.toJson(true, true)); -+ assertEquals(history.getHistory(), roundTripped.getHistory()); - - // Confirm can convert to new-format - String newFormatSerializedHistory = history.toJson(true); -diff --git a/temporal-sdk/src/test/java/io/temporal/workflow/MemoTest.java b/temporal-sdk/src/test/java/io/temporal/workflow/MemoTest.java -index d97f90b..c0e125a 100644 ---- a/temporal-sdk/src/test/java/io/temporal/workflow/MemoTest.java -+++ b/temporal-sdk/src/test/java/io/temporal/workflow/MemoTest.java -@@ -14,7 +14,7 @@ import io.temporal.api.workflowservice.v1.GetWorkflowExecutionHistoryResponse; - import io.temporal.client.WorkflowClient; - import io.temporal.client.WorkflowOptions; - import io.temporal.common.converter.DataConverterException; --import io.temporal.common.converter.GsonJsonPayloadConverter; -+import io.temporal.common.converter.MoshiJsonPayloadConverter; - import io.temporal.internal.client.WorkflowClientHelper; - import io.temporal.testing.internal.SDKTestOptions; - import io.temporal.testing.internal.SDKTestWorkflowRule; -@@ -74,7 +74,7 @@ public class MemoTest { - Memo memoFromEvent = startEvent.getWorkflowExecutionStartedEventAttributes().getMemo(); - Payload memoBytes = memoFromEvent.getFieldsMap().get(MEMO_KEY); - String memoRetrieved = -- GsonJsonPayloadConverter.getInstance().fromData(memoBytes, String.class, String.class); -+ new MoshiJsonPayloadConverter().fromData(memoBytes, String.class, String.class); - assertEquals(MEMO_VALUE, memoRetrieved); - } - --- -2.50.1 (Apple Git-155) - diff --git a/patches/0003-Replace-grpc-netty-shaded-with-grpc-netty.patch b/patches/0002-Replace-grpc-netty-shaded-with-grpc-netty.patch similarity index 100% rename from patches/0003-Replace-grpc-netty-shaded-with-grpc-netty.patch rename to patches/0002-Replace-grpc-netty-shaded-with-grpc-netty.patch diff --git a/patches/0004-Change-groupId-to-com.pkware.temporal.patch b/patches/0003-Change-groupId-to-com.pkware.temporal.patch similarity index 100% rename from patches/0004-Change-groupId-to-com.pkware.temporal.patch rename to patches/0003-Change-groupId-to-com.pkware.temporal.patch diff --git a/patches/0005-Add-Wire-protobuf-support.patch b/patches/0004-Add-Wire-protobuf-support.patch similarity index 100% rename from patches/0005-Add-Wire-protobuf-support.patch rename to patches/0004-Add-Wire-protobuf-support.patch