This is an automated email from the ASF dual-hosted git repository. jianbin pushed a commit to branch 2.x in repository https://gitbox.apache.org/repos/asf/incubator-seata.git
The following commit(s) were added to refs/heads/2.x by this push: new 785b20c7b6 bugfix: raft mode is backward compatible with version 2.0 (#6850) 785b20c7b6 is described below commit 785b20c7b66a4db241c9d5da5b3fab8d41b346f1 Author: funkye <jian...@apache.org> AuthorDate: Fri Sep 13 17:10:45 2024 +0800 bugfix: raft mode is backward compatible with version 2.0 (#6850) --- changes/en-us/2.x.md | 1 + changes/zh-cn/2.x.md | 1 + .../cluster/raft/serializer/CustomDeserializer.java | 1 + .../cluster/raft/serializer/JacksonSerializer.java | 21 +++++++++++++++------ 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/changes/en-us/2.x.md b/changes/en-us/2.x.md index 283808618e..9d10b274be 100644 --- a/changes/en-us/2.x.md +++ b/changes/en-us/2.x.md @@ -44,6 +44,7 @@ Add changes here for all PR submitted to the 2.x branch. - [[#6845](https://github.com/apache/incubator-seata/pull/6845)] fix rocksDB opens the same file multiple times - [[#6840](https://github.com/apache/incubator-seata/pull/6840)] Fix the issue of unsafe deserialization in ProcessorYaml.java - [[#6843](https://github.com/apache/incubator-seata/pull/6843)] Fix 403 error when sending a POST request from the console +- [[#6850](https://github.com/apache/incubator-seata/pull/6850)] raft mode is backward compatible with version 2.0 diff --git a/changes/zh-cn/2.x.md b/changes/zh-cn/2.x.md index 796dd6d1c1..ef8092db89 100644 --- a/changes/zh-cn/2.x.md +++ b/changes/zh-cn/2.x.md @@ -45,6 +45,7 @@ - [[#6845](https://github.com/apache/incubator-seata/pull/6845)] 修复rocksdb open相同文件多次的问题 - [[#6840](https://github.com/apache/incubator-seata/pull/6840)] 修复ProcessorYaml中不安全的反序列化 - [[#6843](https://github.com/apache/incubator-seata/pull/6843)] 修复从控制台发送POST请求时出现的403错误 +- [[#6850](https://github.com/apache/incubator-seata/pull/6850)] raft mode is backward compatible with version 2.0 ### optimize: diff --git a/server/src/main/java/org/apache/seata/server/cluster/raft/serializer/CustomDeserializer.java b/server/src/main/java/org/apache/seata/server/cluster/raft/serializer/CustomDeserializer.java index 6e7a4a0eb9..6f5a6614a5 100644 --- a/server/src/main/java/org/apache/seata/server/cluster/raft/serializer/CustomDeserializer.java +++ b/server/src/main/java/org/apache/seata/server/cluster/raft/serializer/CustomDeserializer.java @@ -40,4 +40,5 @@ public class CustomDeserializer extends JsonDeserializer<Class<?>> { throw new RuntimeException(e.getMessage(), e); } } + } diff --git a/server/src/main/java/org/apache/seata/server/cluster/raft/serializer/JacksonSerializer.java b/server/src/main/java/org/apache/seata/server/cluster/raft/serializer/JacksonSerializer.java index 6674c711ea..e3d802e2d8 100644 --- a/server/src/main/java/org/apache/seata/server/cluster/raft/serializer/JacksonSerializer.java +++ b/server/src/main/java/org/apache/seata/server/cluster/raft/serializer/JacksonSerializer.java @@ -19,6 +19,7 @@ package org.apache.seata.server.cluster.raft.serializer; import java.io.IOException; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.module.SimpleModule; import org.apache.seata.common.loader.LoadLevel; import org.apache.seata.core.serializer.Serializer; @@ -27,13 +28,20 @@ import org.apache.seata.core.serializer.Serializer; @LoadLevel(name = "JACKSON") public class JacksonSerializer implements Serializer { - private final ObjectMapper objectMapper = new ObjectMapper(); + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + + + static { + SimpleModule module = new SimpleModule(); + module.addDeserializer(Class.class,new CustomDeserializer()); + OBJECT_MAPPER.registerModule(module); + } @Override public <T> byte[] serialize(T t) { try { - JsonInfo jsonInfo = new JsonInfo(objectMapper.writeValueAsBytes(t), t.getClass()); - return objectMapper.writeValueAsBytes(jsonInfo); + JsonInfo jsonInfo = new JsonInfo(OBJECT_MAPPER.writeValueAsBytes(t), t.getClass()); + return OBJECT_MAPPER.writeValueAsBytes(jsonInfo); } catch (JsonProcessingException e) { throw new RuntimeException(e); } @@ -42,8 +50,8 @@ public class JacksonSerializer implements Serializer { @Override public <T> T deserialize(byte[] bytes) { try { - JsonInfo jsonInfo = objectMapper.readValue(bytes, JsonInfo.class); - return (T)objectMapper.readValue(jsonInfo.getObj(), jsonInfo.getClz()); + JsonInfo jsonInfo = OBJECT_MAPPER.readValue(bytes, JsonInfo.class); + return (T)OBJECT_MAPPER.readValue(jsonInfo.getObj(), jsonInfo.getClz()); } catch (IOException e) { throw new RuntimeException(e); } @@ -55,7 +63,8 @@ public class JacksonSerializer implements Serializer { Class<?> clz; - public JsonInfo() {} + public JsonInfo() { + } public JsonInfo(byte[] obj, Class<?> clz) { this.obj = obj; --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@seata.apache.org For additional commands, e-mail: notifications-h...@seata.apache.org