Copilot commented on code in PR #9594:
URL: https://github.com/apache/seatunnel/pull/9594#discussion_r2218125257


##########
seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/rest/servlet/BaseServlet.java:
##########
@@ -46,47 +46,55 @@ public BaseServlet(NodeEngineImpl nodeEngine) {
     }
 
     protected void writeJson(HttpServletResponse resp, Object obj) throws 
IOException {
+        resp.setCharacterEncoding(StandardCharsets.UTF_8.toString());
         resp.setContentType("application/json");
         resp.getWriter().write(new Gson().toJson(obj));
     }
 
     protected void writeJson(HttpServletResponse resp, JsonArray jsonArray) 
throws IOException {
+        resp.setCharacterEncoding(StandardCharsets.UTF_8.toString());
         resp.setContentType("application/json");
         resp.getWriter().write(jsonArray.toString());
     }
 
     protected void writeJson(HttpServletResponse resp, JsonObject jsonObject) 
throws IOException {
+        resp.setCharacterEncoding(StandardCharsets.UTF_8.toString());
         resp.setContentType("application/json");
         resp.getWriter().write(jsonObject.toString());
     }
 
     protected void writeJson(HttpServletResponse resp, JsonArray jsonArray, 
int statusCode)
             throws IOException {
+        resp.setCharacterEncoding(StandardCharsets.UTF_8.toString());
         resp.setContentType("application/json");
         resp.setStatus(statusCode);
         resp.getWriter().write(jsonArray.toString());
     }
 
     protected void writeJson(HttpServletResponse resp, JsonObject jsonObject, 
int statusCode)
             throws IOException {
+        resp.setCharacterEncoding(StandardCharsets.UTF_8.toString());
         resp.setContentType("application/json");
         resp.setStatus(statusCode);
         resp.getWriter().write(jsonObject.toString());
     }
 
     protected void writeJson(HttpServletResponse resp, Object obj, int 
statusCode)
             throws IOException {
+        resp.setCharacterEncoding(StandardCharsets.UTF_8.toString());
         resp.setContentType("application/json");
         resp.setStatus(statusCode);
         resp.getWriter().write(new Gson().toJson(obj));
     }
 
     protected void write(HttpServletResponse resp, Object obj) throws 
IOException {
+        resp.setCharacterEncoding(StandardCharsets.UTF_8.toString());
         resp.setContentType("text/plain");
         resp.getWriter().write(obj.toString());
     }
 
     protected void writeHtml(HttpServletResponse resp, Object obj) throws 
IOException {
+        resp.setCharacterEncoding(StandardCharsets.UTF_8.toString());
         resp.setContentType("text/html; charset=UTF-8");

Review Comment:
   The charset specification is redundant in this content type since UTF-8 
encoding is already set via setCharacterEncoding(). Consider using just 
"text/html" for consistency with other methods, or remove the 
setCharacterEncoding() call and rely on the charset in the content type.
   ```suggestion
           resp.setContentType("text/html");
   ```



##########
seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/rest/servlet/BaseServlet.java:
##########
@@ -46,47 +46,55 @@ public BaseServlet(NodeEngineImpl nodeEngine) {
     }
 
     protected void writeJson(HttpServletResponse resp, Object obj) throws 
IOException {
+        resp.setCharacterEncoding(StandardCharsets.UTF_8.toString());
         resp.setContentType("application/json");
         resp.getWriter().write(new Gson().toJson(obj));
     }
 
     protected void writeJson(HttpServletResponse resp, JsonArray jsonArray) 
throws IOException {
+        resp.setCharacterEncoding(StandardCharsets.UTF_8.toString());
         resp.setContentType("application/json");
         resp.getWriter().write(jsonArray.toString());
     }
 
     protected void writeJson(HttpServletResponse resp, JsonObject jsonObject) 
throws IOException {
+        resp.setCharacterEncoding(StandardCharsets.UTF_8.toString());
         resp.setContentType("application/json");
         resp.getWriter().write(jsonObject.toString());
     }
 
     protected void writeJson(HttpServletResponse resp, JsonArray jsonArray, 
int statusCode)
             throws IOException {
+        resp.setCharacterEncoding(StandardCharsets.UTF_8.toString());

Review Comment:
   Consider using StandardCharsets.UTF_8.name() instead of toString() for 
better performance. The name() method is specifically designed for charset 
names, while toString() is a general object method.
   ```suggestion
           resp.setCharacterEncoding(StandardCharsets.UTF_8.name());
           resp.setContentType("application/json");
           resp.getWriter().write(new Gson().toJson(obj));
       }
   
       protected void writeJson(HttpServletResponse resp, JsonArray jsonArray) 
throws IOException {
           resp.setCharacterEncoding(StandardCharsets.UTF_8.name());
           resp.setContentType("application/json");
           resp.getWriter().write(jsonArray.toString());
       }
   
       protected void writeJson(HttpServletResponse resp, JsonObject 
jsonObject) throws IOException {
           resp.setCharacterEncoding(StandardCharsets.UTF_8.name());
           resp.setContentType("application/json");
           resp.getWriter().write(jsonObject.toString());
       }
   
       protected void writeJson(HttpServletResponse resp, JsonArray jsonArray, 
int statusCode)
               throws IOException {
           resp.setCharacterEncoding(StandardCharsets.UTF_8.name());
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to