jonyangx commented on code in PR #2318:
URL: 
https://github.com/apache/incubator-eventmesh/pull/2318#discussion_r1036591594


##########
eventmesh-common/src/main/java/org/apache/eventmesh/common/utils/JsonUtils.java:
##########
@@ -42,29 +52,53 @@ public class JsonUtils {
      * @return json string
      */
     public static String serialize(Object obj) {
+        if (Objects.isNull(obj)) {
+            return null;
+        }
         try {
             return OBJECT_MAPPER.writeValueAsString(obj);
         } catch (JsonProcessingException e) {
             throw new JsonException("serialize to json error", e);
         }
     }
 
+    public static <T> byte[] serialize(String topic, Class<T> data) throws 
JsonProcessingException {
+        if (data == null) {
+            return null;
+        }
+        return OBJECT_MAPPER.writeValueAsBytes(data);
+    }
+
     /**
      * Deserialize json string to object.
      *
-     * @param str json string
-     * @param clz object class
-     * @param <T> object type
+     * @param json json string
+     * @param clz  object class
+     * @param <T>  object type
      * @return object
      */
-    public static <T> T deserialize(String str, Class<T> clz) {
+    public static <T> T deserialize(String json, Class<T> clz) {
+        if (StringUtils.isEmpty(json)) {
+            return null;
+        }
         try {
-            return OBJECT_MAPPER.readValue(str, clz);
+            return OBJECT_MAPPER.readValue(json, clz);
         } catch (JsonProcessingException e) {
             throw new JsonException("deserialize json string to object error", 
e);
         }
     }
 
+    public static <T> T deserialize(Class<T> clazz, byte[] bytes) throws 
IOException {

Review Comment:
   suggest refactor throw exception.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to