Refactor: centralize Gson instantiation

The creation of Gson instances has been centralized in the GsonUtils
class to improve code maintainability and consistency across the
application.

Change-Id: Iaad2ec6e9214469c7a5b0df2268681e57cd38f8c
Signed-off-by: Patrizio <patrizio.gelosi@amarulasolutions.com>
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/PatchSetReviewer.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/PatchSetReviewer.java
index 01e3b69..b2f54de 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/PatchSetReviewer.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/PatchSetReviewer.java
@@ -1,6 +1,5 @@
 package com.googlesource.gerrit.plugins.chatgpt;
 
-import com.google.gson.Gson;
 import com.google.inject.Inject;
 import com.googlesource.gerrit.plugins.chatgpt.config.Configuration;
 import com.googlesource.gerrit.plugins.chatgpt.data.ChangeSetDataHandler;
@@ -24,13 +23,13 @@
 import java.util.*;
 
 import static com.googlesource.gerrit.plugins.chatgpt.utils.ClassUtils.registerDynamicClasses;
+import static com.googlesource.gerrit.plugins.chatgpt.utils.GsonUtils.getGson;
 
 @Slf4j
 public class PatchSetReviewer {
     private static final String SPLIT_REVIEW_MSG = "Too many changes. Please consider splitting into patches smaller " +
             "than %s lines for review.";
 
-    private final Gson gson = new Gson();
     private final GerritClient gerritClient;
 
     private Configuration config;
@@ -96,7 +95,7 @@
     }
 
     private void retrieveReviewBatches(String reviewReply, GerritChange change) {
-        ChatGptResponseContent reviewJson = gson.fromJson(reviewReply, ChatGptResponseContent.class);
+        ChatGptResponseContent reviewJson = getGson().fromJson(reviewReply, ChatGptResponseContent.class);
         ChangeSetData changeSetData = ChangeSetDataHandler.getInstance(change);
         for (ChatGptReplyItem replyItem : reviewJson.getReplies()) {
             String reply = replyItem.getReply();
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/api/chatgpt/ChatGptTools.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/api/chatgpt/ChatGptTools.java
index 30fff94..4053cfe 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/api/chatgpt/ChatGptTools.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/api/chatgpt/ChatGptTools.java
@@ -1,19 +1,18 @@
 package com.googlesource.gerrit.plugins.chatgpt.mode.common.client.api.chatgpt;
 
-import com.google.gson.Gson;
 import com.googlesource.gerrit.plugins.chatgpt.mode.common.model.api.chatgpt.ChatGptRequest;
 import com.googlesource.gerrit.plugins.chatgpt.utils.FileUtils;
 
 import java.io.IOException;
 import java.io.InputStreamReader;
 
-public class ChatGptTools {
-    private final static Gson gson = new Gson();
+import static com.googlesource.gerrit.plugins.chatgpt.utils.GsonUtils.getGson;
 
+public class ChatGptTools {
     public static ChatGptRequest retrieveTools() {
         ChatGptRequest tools;
         try (InputStreamReader reader = FileUtils.getInputStreamReader("Config/tools.json")) {
-            tools = gson.fromJson(reader, ChatGptRequest.class);
+            tools = getGson().fromJson(reader, ChatGptRequest.class);
         } catch (IOException e) {
             throw new RuntimeException("Failed to load ChatGPT request tools", e);
         }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/api/gerrit/GerritClientBase.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/api/gerrit/GerritClientBase.java
index e11797b..4bdc525 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/api/gerrit/GerritClientBase.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/api/gerrit/GerritClientBase.java
@@ -1,7 +1,6 @@
 package com.googlesource.gerrit.plugins.chatgpt.mode.common.client.api.gerrit;
 
 import com.google.common.net.HttpHeaders;
-import com.google.gson.Gson;
 import com.google.gson.JsonArray;
 import com.google.gson.JsonObject;
 import com.googlesource.gerrit.plugins.chatgpt.config.Configuration;
@@ -18,13 +17,13 @@
 import java.nio.charset.StandardCharsets;
 import java.util.*;
 
+import static com.googlesource.gerrit.plugins.chatgpt.utils.GsonUtils.getGson;
 import static java.net.HttpURLConnection.HTTP_OK;
 
 
 @Slf4j
 public abstract class GerritClientBase extends ClientBase {
     protected final HttpClientWithRetry httpClientWithRetry = new HttpClientWithRetry();
-    protected final Gson gson = new Gson();
     @Getter
     protected HashMap<String, FileDiffProcessed> fileDiffsProcessed = new HashMap<>();
 
@@ -58,12 +57,12 @@
 
     protected JsonArray forwardGetRequestReturnJsonArray(URI uri) throws Exception {
         String responseBody = forwardGetRequest(uri);
-        return gson.fromJson(responseBody, JsonArray.class);
+        return getGson().fromJson(responseBody, JsonArray.class);
     }
 
     protected JsonObject forwardGetRequestReturnJsonObject(URI uri) throws Exception {
         String responseBody = forwardGetRequest(uri);
-        return gson.fromJson(responseBody, JsonObject.class);
+        return getGson().fromJson(responseBody, JsonObject.class);
     }
 
 }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/api/gerrit/GerritClientComments.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/api/gerrit/GerritClientComments.java
index e7b22a9..cd383fe 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/api/gerrit/GerritClientComments.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/api/gerrit/GerritClientComments.java
@@ -14,6 +14,7 @@
 import java.net.URI;
 import java.util.*;
 
+import static com.googlesource.gerrit.plugins.chatgpt.utils.GsonUtils.getGson;
 import static com.googlesource.gerrit.plugins.chatgpt.utils.TimeUtils.getTimeStamp;
 import static com.googlesource.gerrit.plugins.chatgpt.settings.Settings.GERRIT_PATCH_SET_FILENAME;
 
@@ -69,7 +70,7 @@
                 + UriResourceLocator.gerritGetAllPatchSetCommentsUri(change.getFullChangeId()));
         String responseBody = forwardGetRequest(uri);
         Type mapEntryType = new TypeToken<Map<String, List<GerritComment>>>(){}.getType();
-        Map<String, List<GerritComment>> lastCommentMap = gson.fromJson(responseBody, mapEntryType);
+        Map<String, List<GerritComment>> lastCommentMap = getGson().fromJson(responseBody, mapEntryType);
 
         String latestChangeMessageId = null;
         HashMap<String, List<GerritComment>> latestComments = new HashMap<>();
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/api/gerrit/GerritClientDetail.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/api/gerrit/GerritClientDetail.java
index 3432928..1049c59 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/api/gerrit/GerritClientDetail.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/api/gerrit/GerritClientDetail.java
@@ -11,6 +11,8 @@
 import java.net.URI;
 import java.util.List;
 
+import static com.googlesource.gerrit.plugins.chatgpt.utils.GsonUtils.getGson;
+
 @Slf4j
 public class GerritClientDetail extends GerritClientBase {
     private GerritPatchSetDetail gerritPatchSetDetail;
@@ -62,7 +64,7 @@
         URI uri = URI.create(config.getGerritAuthBaseUrl()
                 + UriResourceLocator.gerritGetPatchSetDetailUri(fullChangeId));
         String responseBody = forwardGetRequest(uri);
-        return gson.fromJson(responseBody, GerritPatchSetDetail.class);
+        return getGson().fromJson(responseBody, GerritPatchSetDetail.class);
     }
 
 }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/api/gerrit/GerritClientReview.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/api/gerrit/GerritClientReview.java
index 2559d6a..edc77ee 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/api/gerrit/GerritClientReview.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/api/gerrit/GerritClientReview.java
@@ -19,6 +19,7 @@
 
 import static com.googlesource.gerrit.plugins.chatgpt.mode.common.client.prompt.MessageSanitizer.sanitizeChatGptMessage;
 import static com.googlesource.gerrit.plugins.chatgpt.settings.Settings.EMPTY_REVIEW_MESSAGE;
+import static com.googlesource.gerrit.plugins.chatgpt.utils.GsonUtils.getGson;
 import static java.net.HttpURLConnection.HTTP_OK;
 
 @Slf4j
@@ -37,7 +38,7 @@
         log.debug("Set-Review uri: {}", uri);
         String auth = generateBasicAuth(config.getGerritUserName(),
                 config.getGerritPassword());
-        String json = gson.toJson(reviewMap);
+        String json = getGson().toJson(reviewMap);
         log.debug("Set-Review JSON: {}", json);
         HttpRequest request = HttpRequest.newBuilder()
                 .header(HttpHeaders.AUTHORIZATION, auth)
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/prompt/ChatGptPrompt.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/prompt/ChatGptPrompt.java
index 6f95313..8b53b30 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/prompt/ChatGptPrompt.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/prompt/ChatGptPrompt.java
@@ -1,6 +1,5 @@
 package com.googlesource.gerrit.plugins.chatgpt.mode.common.client.prompt;
 
-import com.google.gson.Gson;
 import com.google.gson.reflect.TypeToken;
 import com.googlesource.gerrit.plugins.chatgpt.config.Configuration;
 import com.googlesource.gerrit.plugins.chatgpt.data.ChangeSetDataHandler;
@@ -15,6 +14,7 @@
 import java.util.*;
 import java.util.stream.Collectors;
 
+import static com.googlesource.gerrit.plugins.chatgpt.utils.GsonUtils.getGson;
 import static com.googlesource.gerrit.plugins.chatgpt.utils.TextUtils.*;
 
 @Slf4j
@@ -187,10 +187,9 @@
     private void loadPrompts() {
         // Avoid repeated loading of prompt constants
         if (DEFAULT_GPT_SYSTEM_PROMPT != null) return;
-        Gson gson = new Gson();
         Class<? extends ChatGptPrompt> me = this.getClass();
         try (InputStreamReader reader = FileUtils.getInputStreamReader("Config/prompts.json")) {
-            Map<String, Object> values = gson.fromJson(reader, new TypeToken<Map<String, Object>>(){}.getType());
+            Map<String, Object> values = getGson().fromJson(reader, new TypeToken<Map<String, Object>>(){}.getType());
             for (Map.Entry<String, Object> entry : values.entrySet()) {
                 try {
                     Field field = me.getDeclaredField(entry.getKey());
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/prompt/ChatGptUserPrompt.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/prompt/ChatGptUserPrompt.java
index fc61d63..244899c 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/prompt/ChatGptUserPrompt.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/prompt/ChatGptUserPrompt.java
@@ -1,6 +1,5 @@
 package com.googlesource.gerrit.plugins.chatgpt.mode.common.client.prompt;
 
-import com.google.gson.Gson;
 import com.googlesource.gerrit.plugins.chatgpt.config.Configuration;
 import com.googlesource.gerrit.plugins.chatgpt.mode.common.client.api.gerrit.GerritChange;
 import com.googlesource.gerrit.plugins.chatgpt.mode.common.model.api.chatgpt.ChatGptMessageItem;
@@ -9,10 +8,11 @@
 
 import java.util.List;
 
+import static com.googlesource.gerrit.plugins.chatgpt.utils.GsonUtils.getGson;
+
 @Slf4j
 public class ChatGptUserPrompt {
     private final ChatGptUserPromptBase chatGptUserPromptBase;
-    private final Gson gson = new Gson();
 
     public ChatGptUserPrompt(Configuration config, GerritChange change, GerritClientData gerritClientData) {
         if (change.getIsCommentEvent()) {
@@ -28,7 +28,7 @@
             chatGptUserPromptBase.addMessageItem(i);
         }
         List<ChatGptMessageItem> messageItems = chatGptUserPromptBase.getMessageItems();
-        return messageItems.isEmpty() ? "" : gson.toJson(messageItems);
+        return messageItems.isEmpty() ? "" : getGson().toJson(messageItems);
     }
 
 }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateless/client/api/chatgpt/ChatGptClientStateless.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateless/client/api/chatgpt/ChatGptClientStateless.java
index 51d3967..8491a0a 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateless/client/api/chatgpt/ChatGptClientStateless.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateless/client/api/chatgpt/ChatGptClientStateless.java
@@ -1,8 +1,6 @@
 package com.googlesource.gerrit.plugins.chatgpt.mode.stateless.client.api.chatgpt;
 
 import com.google.common.net.HttpHeaders;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
 import com.google.inject.Singleton;
 import com.googlesource.gerrit.plugins.chatgpt.config.Configuration;
 import com.googlesource.gerrit.plugins.chatgpt.mode.common.client.HttpClientWithRetry;
@@ -25,15 +23,15 @@
 import java.util.List;
 import java.util.Optional;
 
+import static com.googlesource.gerrit.plugins.chatgpt.utils.GsonUtils.getGson;
+import static com.googlesource.gerrit.plugins.chatgpt.utils.GsonUtils.getNoEscapedGson;
+
 @Slf4j
 @Singleton
 public class ChatGptClientStateless implements IChatGptClient {
     private static final int REVIEW_ATTEMPT_LIMIT = 3;
     @Getter
     private String requestBody;
-    private final Gson gson = new GsonBuilder()
-            .disableHtmlEscaping()
-            .create();
     private final HttpClientWithRetry httpClientWithRetry = new HttpClientWithRetry();
     private boolean isCommentEvent = false;
 
@@ -79,13 +77,14 @@
         }
         else {
             ChatGptResponseUnstreamed chatGptResponseUnstreamed =
-                    gson.fromJson(body, ChatGptResponseUnstreamed.class);
+                    getGson().fromJson(body, ChatGptResponseUnstreamed.class);
             return getResponseContent(chatGptResponseUnstreamed.getChoices().get(0).getMessage().getToolCalls());
         }
     }
 
     private boolean validateResponse(String contentExtracted, String changeId, int attemptInd) {
-        ChatGptResponseContent chatGptResponseContent = gson.fromJson(contentExtracted, ChatGptResponseContent.class);
+        ChatGptResponseContent chatGptResponseContent =
+                getGson().fromJson(contentExtracted, ChatGptResponseContent.class);
         String returnedChangeId = chatGptResponseContent.getChangeId();
         // A response is considered valid if either no changeId is returned or the changeId returned matches the one
         // provided in the request
@@ -140,7 +139,7 @@
                 .toolChoice(tools.getToolChoice())
                 .build();
 
-        return gson.toJson(chatGptRequest);
+        return getNoEscapedGson().toJson(chatGptRequest);
     }
 
     private Optional<String> extractContentFromLine(String line) {
@@ -150,7 +149,7 @@
             return Optional.empty();
         }
         ChatGptResponseStreamed chatGptResponseStreamed =
-                gson.fromJson(line.substring("data: ".length()), ChatGptResponseStreamed.class);
+                getGson().fromJson(line.substring("data: ".length()), ChatGptResponseStreamed.class);
         ChatGptResponseMessage delta = chatGptResponseStreamed.getChoices().get(0).getDelta();
         if (delta == null || delta.getToolCalls() == null) {
             return Optional.empty();
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateless/client/api/gerrit/GerritClientPatchSetStateless.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateless/client/api/gerrit/GerritClientPatchSetStateless.java
index 2c770ea..5a1f160 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateless/client/api/gerrit/GerritClientPatchSetStateless.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateless/client/api/gerrit/GerritClientPatchSetStateless.java
@@ -1,7 +1,5 @@
 package com.googlesource.gerrit.plugins.chatgpt.mode.stateless.client.api.gerrit;
 
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
 import com.google.gson.JsonElement;
 import com.google.gson.JsonObject;
 import com.googlesource.gerrit.plugins.chatgpt.config.Configuration;
@@ -19,11 +17,11 @@
 import java.util.List;
 import java.util.Map;
 
+import static com.googlesource.gerrit.plugins.chatgpt.utils.GsonUtils.getGson;
+import static com.googlesource.gerrit.plugins.chatgpt.utils.GsonUtils.getNoEscapedGson;
+
 @Slf4j
 public class GerritClientPatchSetStateless extends GerritClientPatchSet implements IGerritClientPatchSet {
-    private final Gson gson = new GsonBuilder()
-            .disableHtmlEscaping()
-            .create();
     private final List<String> diffs;
     private boolean isCommitMessage;
 
@@ -70,14 +68,14 @@
 
     private void processFileDiff(String filename, String fileDiffJson) {
         log.debug("FileDiff Json processed: {}", fileDiffJson);
-        GerritPatchSetFileDiff gerritPatchSetFileDiff = gson.fromJson(fileDiffJson, GerritPatchSetFileDiff.class);
+        GerritPatchSetFileDiff gerritPatchSetFileDiff = getGson().fromJson(fileDiffJson, GerritPatchSetFileDiff.class);
         // Initialize the reduced file diff for the Gerrit review with fields `meta_a` and `meta_b`
         GerritReviewFileDiff gerritReviewFileDiff = new GerritReviewFileDiff(gerritPatchSetFileDiff.getMetaA(),
                 gerritPatchSetFileDiff.getMetaB());
         FileDiffProcessed fileDiffProcessed = new FileDiffProcessed(config, isCommitMessage, gerritPatchSetFileDiff);
         fileDiffsProcessed.put(filename, fileDiffProcessed);
         gerritReviewFileDiff.setContent(fileDiffProcessed.getReviewDiffContent());
-        diffs.add(gson.toJson(gerritReviewFileDiff));
+        diffs.add(getNoEscapedGson().toJson(gerritReviewFileDiff));
     }
 
     private String getFileDiffsJson(String fullChangeId, List<String> files, int revisionBase) throws Exception {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/utils/GsonUtils.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/utils/GsonUtils.java
new file mode 100644
index 0000000..721de45
--- /dev/null
+++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/utils/GsonUtils.java
@@ -0,0 +1,17 @@
+package com.googlesource.gerrit.plugins.chatgpt.utils;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+public class GsonUtils {
+    public static Gson getGson() {
+        return new Gson();
+    }
+
+    public static Gson getNoEscapedGson() {
+        return new GsonBuilder()
+                .disableHtmlEscaping()
+                .create();
+    }
+
+}
diff --git a/src/test/java/com/googlesource/gerrit/plugins/chatgpt/ChatGptReviewTest.java b/src/test/java/com/googlesource/gerrit/plugins/chatgpt/ChatGptReviewTest.java
index 9565234..638b74b 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/chatgpt/ChatGptReviewTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/chatgpt/ChatGptReviewTest.java
@@ -15,7 +15,6 @@
 import com.google.gerrit.server.events.PatchSetCreatedEvent;
 import com.google.gerrit.server.project.NoSuchProjectException;
 import com.google.gson.JsonArray;
-import com.google.gson.Gson;
 import com.google.gson.JsonObject;
 import com.googlesource.gerrit.plugins.chatgpt.config.ConfigCreator;
 import com.googlesource.gerrit.plugins.chatgpt.config.Configuration;
@@ -51,6 +50,7 @@
 
 import static com.google.gerrit.extensions.client.ChangeKind.REWORK;
 import static com.googlesource.gerrit.plugins.chatgpt.mode.common.client.UriResourceLocator.*;
+import static com.googlesource.gerrit.plugins.chatgpt.utils.GsonUtils.getGson;
 import static com.googlesource.gerrit.plugins.chatgpt.utils.TextUtils.joinWithNewLine;
 import static java.net.HttpURLConnection.HTTP_OK;
 import static org.mockito.Mockito.mock;
@@ -77,8 +77,6 @@
     private static final boolean GPT_STREAM_OUTPUT = true;
     private static final long TEST_TIMESTAMP = 1699270812;
 
-    private final Gson gson = new Gson();
-
     private String expectedResponseStreamed;
     private String expectedSystemPromptReview;
     private String promptTagReview;
@@ -289,7 +287,7 @@
                 WireMock.urlEqualTo(gerritSetReviewUri(getGerritChange().getFullChangeId())));
         List<LoggedRequest> loggedRequests = WireMock.findAll(requestPatternBuilder);
         Assert.assertEquals(1, loggedRequests.size());
-        JsonObject gptRequestBody = gson.fromJson(patchSetReviewer.getChatGptClient().getRequestBody(), JsonObject.class);
+        JsonObject gptRequestBody = getGson().fromJson(patchSetReviewer.getChatGptClient().getRequestBody(), JsonObject.class);
         JsonArray prompts = gptRequestBody.get("messages").getAsJsonArray();
         String systemPrompt = prompts.get(0).getAsJsonObject().get("content").getAsString();
         Assert.assertEquals(expectedSystemPromptReview, systemPrompt);
@@ -345,7 +343,7 @@
                 WireMock.urlEqualTo(gerritSetReviewUri(getGerritChange().getFullChangeId())));
         List<LoggedRequest> loggedRequests = WireMock.findAll(requestPatternBuilder);
         Assert.assertEquals(1, loggedRequests.size());
-        JsonObject gptRequestBody = gson.fromJson(patchSetReviewer.getChatGptClient().getRequestBody(), JsonObject.class);
+        JsonObject gptRequestBody = getGson().fromJson(patchSetReviewer.getChatGptClient().getRequestBody(), JsonObject.class);
         JsonArray prompts = gptRequestBody.get("messages").getAsJsonArray();
         String userPrompt = prompts.get(1).getAsJsonObject().get("content").getAsString();
         Assert.assertEquals(reviewVoteUserPrompt, userPrompt);
@@ -421,7 +419,7 @@
                 WireMock.urlEqualTo(gerritSetReviewUri(gerritChange.getFullChangeId())));
         List<LoggedRequest> loggedRequests = WireMock.findAll(requestPatternBuilder);
         Assert.assertEquals(1, loggedRequests.size());
-        JsonObject gptRequestBody = gson.fromJson(patchSetReviewer.getChatGptClient().getRequestBody(), JsonObject.class);
+        JsonObject gptRequestBody = getGson().fromJson(patchSetReviewer.getChatGptClient().getRequestBody(), JsonObject.class);
         JsonArray prompts = gptRequestBody.get("messages").getAsJsonArray();
         String userPrompt = prompts.get(1).getAsJsonObject().get("content").getAsString();
         Assert.assertEquals(commentUserPrompt, userPrompt);