This is an automated email from the ASF dual-hosted git repository.

funky-eyes 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 8c202b949e refactor: Change the old JSON configuration items to the 
new ones (#8067)
8c202b949e is described below

commit 8c202b949e695a6f9c18852fa30ea7cb50e6b17b
Author: legendpei <[email protected]>
AuthorDate: Sat May 9 11:17:53 2026 +0800

    refactor: Change the old JSON configuration items to the new ones (#8067)
---
 changes/en-us/2.x.md                               |  2 +-
 changes/zh-cn/2.x.md                               |  1 +
 .../org/apache/seata/common/ConfigurationKeys.java | 11 ++++
 .../org/apache/seata/common/DefaultValues.java     |  9 +++-
 .../org/apache/seata/common/json/JsonUtil.java     | 35 ++++++++++---
 .../org/apache/seata/common/json/JsonUtilTest.java | 58 +++++++++++++++++++---
 script/client/spring/application.properties        |  5 +-
 script/client/spring/application.yml               |  5 +-
 .../properties/SeataJsonProperties.java            | 19 +++++++
 .../properties/SeataTccProperties.java             | 12 +++++
 .../properties/SeataJsonPropertiesTest.java        |  3 ++
 11 files changed, 140 insertions(+), 20 deletions(-)

diff --git a/changes/en-us/2.x.md b/changes/en-us/2.x.md
index f2af64baee..ce6b679e06 100644
--- a/changes/en-us/2.x.md
+++ b/changes/en-us/2.x.md
@@ -85,7 +85,7 @@ Add changes here for all PR submitted to the 2.x branch.
 - [[#7957](https://github.com/apache/incubator-seata/pull/7957)] replace 
Apache HttpClient with OkHttp in NamingServer
 - [[#8023](https://github.com/apache/incubator-seata/pull/8023)] supports 
global switching of virtual threads
 - [[#8055](https://github.com/apache/incubator-seata/pull/8055)] set the value 
of DEFAULT_TCC_BUSINESS_ACTION_CONTEXT_JSON_PARSER from fastjson to jackson
-
+- [[#8067](https://github.com/apache/incubator-seata/pull/8067)] Change the 
old JSON configuration items to the new ones
 
 ### doc:
 
diff --git a/changes/zh-cn/2.x.md b/changes/zh-cn/2.x.md
index 0b0f4d99a8..30dd88a9eb 100644
--- a/changes/zh-cn/2.x.md
+++ b/changes/zh-cn/2.x.md
@@ -89,6 +89,7 @@
 - [[#7957](https://github.com/apache/incubator-seata/pull/7957)] 在 
NamingServer 用 OkHttp 替换 Apache HttpClient 
 - [[#8023](https://github.com/apache/incubator-seata/pull/8023)] 支持全局切换虚拟线程
 - [[#8055](https://github.com/apache/incubator-seata/pull/8055)] 
将DEFAULT_TCC_BUSINESS_ACTION_CONTEXT_JSON_PARSER的值从fastjson设置为jackson
+- [[#8067](https://github.com/apache/incubator-seata/pull/8067)] 将旧的 JSON 
配置项更改为新的
 
 
 ### doc:
diff --git 
a/common/src/main/java/org/apache/seata/common/ConfigurationKeys.java 
b/common/src/main/java/org/apache/seata/common/ConfigurationKeys.java
index a3be30a5b6..e31bc8e72e 100644
--- a/common/src/main/java/org/apache/seata/common/ConfigurationKeys.java
+++ b/common/src/main/java/org/apache/seata/common/ConfigurationKeys.java
@@ -967,6 +967,11 @@ public interface ConfigurationKeys {
      */
     String TCC_PREFIX = "tcc.";
 
+    /**
+     * The constant JSON_PREFIX
+     */
+    String JSON_PREFIX = "json.";
+
     /**
      * The constant TCC_FENCE_PREFIX
      */
@@ -982,9 +987,15 @@ public interface ConfigurationKeys {
      */
     String TCC_FENCE_LOG_TABLE_NAME = TCC_FENCE_PREFIX + "logTableName";
 
+    /**
+     * The constant JSON_SERIALIZER_TYPE
+     */
+    String JSON_SERIALIZER_TYPE = JSON_PREFIX + "serializerType";
+
     /**
      * The constant TCC_BUSINESS_ACTION_CONTEXT_JSON_PARSER_NAME
      */
+    @Deprecated
     String TCC_BUSINESS_ACTION_CONTEXT_JSON_PARSER_NAME = TCC_PREFIX + 
"contextJsonParserType";
 
     /**
diff --git a/common/src/main/java/org/apache/seata/common/DefaultValues.java 
b/common/src/main/java/org/apache/seata/common/DefaultValues.java
index 4b53776264..9c1c0cd4c9 100644
--- a/common/src/main/java/org/apache/seata/common/DefaultValues.java
+++ b/common/src/main/java/org/apache/seata/common/DefaultValues.java
@@ -346,11 +346,16 @@ public interface DefaultValues {
      */
     String DEFAULT_SAGA_JSON_PARSER = "fastjson";
 
+    /**
+     * The default global JSON serializer.
+     */
+    String BUSINESS_ACTION_CONTEXT_JSON_PARSER = "jackson";
+
     /**
      * The constant DEFAULT_TCC_BUSINESS_ACTION_CONTEXT_JSON_PARSER.
      */
-    // default tcc business action context json parser
-    String DEFAULT_TCC_BUSINESS_ACTION_CONTEXT_JSON_PARSER = "jackson";
+    @Deprecated
+    String DEFAULT_TCC_BUSINESS_ACTION_CONTEXT_JSON_PARSER = 
BUSINESS_ACTION_CONTEXT_JSON_PARSER;
 
     /**
      * The constant DEFAULT_SERVER_ENABLE_CHECK_AUTH.
diff --git 
a/json-common/json-common-core/src/main/java/org/apache/seata/common/json/JsonUtil.java
 
b/json-common/json-common-core/src/main/java/org/apache/seata/common/json/JsonUtil.java
index 33dc6b16a8..574edf5307 100644
--- 
a/json-common/json-common-core/src/main/java/org/apache/seata/common/json/JsonUtil.java
+++ 
b/json-common/json-common-core/src/main/java/org/apache/seata/common/json/JsonUtil.java
@@ -20,7 +20,11 @@ import org.apache.seata.common.ConfigurationKeys;
 import org.apache.seata.common.Constants;
 import org.apache.seata.common.DefaultValues;
 import org.apache.seata.common.exception.JsonParseException;
+import org.apache.seata.common.util.StringUtils;
+import org.apache.seata.config.Configuration;
 import org.apache.seata.config.ConfigurationFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.util.Objects;
 
@@ -29,13 +33,32 @@ import java.util.Objects;
  */
 public final class JsonUtil {
 
-    private static final String CONFIG_JSON_PARSER_NAME = 
ConfigurationFactory.getInstance()
-            .getConfig(
-                    
ConfigurationKeys.TCC_BUSINESS_ACTION_CONTEXT_JSON_PARSER_NAME,
-                    
DefaultValues.DEFAULT_TCC_BUSINESS_ACTION_CONTEXT_JSON_PARSER);
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(JsonUtil.class);
+
+    private static final String CONFIG_JSON_SERIALIZER_NAME =
+            resolveJsonSerializerName(ConfigurationFactory.getInstance());
 
     private static final JsonSerializer DEFAULT_SERIALIZER =
-            JsonSerializerFactory.getSerializer(CONFIG_JSON_PARSER_NAME);
+            JsonSerializerFactory.getSerializer(CONFIG_JSON_SERIALIZER_NAME);
+
+    static String resolveJsonSerializerName(Configuration configuration) {
+        String serializerType = 
configuration.getConfig(ConfigurationKeys.JSON_SERIALIZER_TYPE);
+        if (StringUtils.isNotBlank(serializerType)) {
+            return serializerType;
+        }
+
+        String deprecatedSerializerType =
+                
configuration.getConfig(ConfigurationKeys.TCC_BUSINESS_ACTION_CONTEXT_JSON_PARSER_NAME);
+        if (StringUtils.isNotBlank(deprecatedSerializerType)) {
+            LOGGER.warn(
+                    "The config '{}' is deprecated since 2.7.0 and will be 
removed in a future version. Please use '{}' instead.",
+                    
ConfigurationKeys.TCC_BUSINESS_ACTION_CONTEXT_JSON_PARSER_NAME,
+                    ConfigurationKeys.JSON_SERIALIZER_TYPE);
+            return deprecatedSerializerType;
+        }
+
+        return DefaultValues.BUSINESS_ACTION_CONTEXT_JSON_PARSER;
+    }
 
     /**
      * Serialize the given object to JSON string
@@ -63,7 +86,7 @@ public final class JsonUtil {
         }
         String jsonParseName = 
text.startsWith(Constants.JACKSON_JSON_TEXT_PREFIX)
                 ? Constants.JACKSON_JSON_PARSER_NAME
-                : CONFIG_JSON_PARSER_NAME;
+                : CONFIG_JSON_SERIALIZER_NAME;
         return 
JsonSerializerFactory.getSerializer(jsonParseName).parseObject(text, clazz);
     }
 }
diff --git 
a/json-common/json-common-core/src/test/java/org/apache/seata/common/json/JsonUtilTest.java
 
b/json-common/json-common-core/src/test/java/org/apache/seata/common/json/JsonUtilTest.java
index 54e0c8afb7..2dab9ba4ec 100644
--- 
a/json-common/json-common-core/src/test/java/org/apache/seata/common/json/JsonUtilTest.java
+++ 
b/json-common/json-common-core/src/test/java/org/apache/seata/common/json/JsonUtilTest.java
@@ -16,10 +16,15 @@
  */
 package org.apache.seata.common.json;
 
+import org.apache.seata.common.ConfigurationKeys;
+import org.apache.seata.common.DefaultValues;
+import org.apache.seata.config.Configuration;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 
 public class JsonUtilTest {
 
@@ -27,7 +32,7 @@ public class JsonUtilTest {
     void setUp() {}
 
     @Test
-    public void testToJSONString_basicObject() {
+    public void testToJSONStringBasicObject() {
         TestObject obj = new TestObject("test", 123);
         String json = JsonUtil.toJSONString(obj);
 
@@ -37,7 +42,7 @@ public class JsonUtilTest {
     }
 
     @Test
-    public void testParseObject_basicObject() {
+    public void testParseObjectBasicObject() {
         String json = "{\"name\":\"test\",\"value\":123}";
         TestObject obj = JsonUtil.parseObject(json, TestObject.class);
 
@@ -47,7 +52,7 @@ public class JsonUtilTest {
     }
 
     @Test
-    public void testToJSONString_and_parseObject_apple() {
+    public void testToJSONStringAndParseObjectApple() {
         TestObject original = new TestObject("apple", 456);
         String json = JsonUtil.toJSONString(original);
         TestObject restored = JsonUtil.parseObject(json, TestObject.class);
@@ -57,7 +62,7 @@ public class JsonUtilTest {
     }
 
     @Test
-    public void testParseObject_nullInputs() {
+    public void testParseObjectNullInputs() {
         TestObject obj1 = JsonUtil.parseObject(null, TestObject.class);
         assertThat(obj1).isNull();
 
@@ -66,7 +71,7 @@ public class JsonUtilTest {
     }
 
     @Test
-    public void testParseObject_prefixLogic() {
+    public void testParseObjectPrefixLogic() {
         String normalJson = "{\"name\":\"normalTest\",\"value\":888}";
         TestObject obj = JsonUtil.parseObject(normalJson, TestObject.class);
         assertThat(obj).isNotNull();
@@ -75,13 +80,13 @@ public class JsonUtilTest {
     }
 
     @Test
-    public void testToJSONString_nullObject() {
+    public void testToJSONStringNullObject() {
         String json = JsonUtil.toJSONString(null);
         assertThat(json).isEqualTo("null");
     }
 
     @Test
-    public void testParseObject_complexObject() {
+    public void testParseObjectComplexObject() {
         ComplexTestObject complexObj = new ComplexTestObject();
         complexObj.setName("complex");
         complexObj.setValue(789);
@@ -98,6 +103,45 @@ public class JsonUtilTest {
         assertThat(restored.getNested().getValue()).isEqualTo(1);
     }
 
+    @Test
+    public void testResolveJsonSerializerNamePrefersNewConfig() {
+        Configuration configuration = mock(Configuration.class);
+        
when(configuration.getConfig(ConfigurationKeys.JSON_SERIALIZER_TYPE)).thenReturn("gson");
+
+        
assertThat(JsonUtil.resolveJsonSerializerName(configuration)).isEqualTo("gson");
+    }
+
+    @Test
+    public void testResolveJsonSerializerNameFallsBackToDeprecatedConfig() {
+        Configuration configuration = mock(Configuration.class);
+        
when(configuration.getConfig(ConfigurationKeys.JSON_SERIALIZER_TYPE)).thenReturn(null);
+        
when(configuration.getConfig(ConfigurationKeys.TCC_BUSINESS_ACTION_CONTEXT_JSON_PARSER_NAME))
+                .thenReturn("fastjson2");
+
+        
assertThat(JsonUtil.resolveJsonSerializerName(configuration)).isEqualTo("fastjson2");
+    }
+
+    @Test
+    public void testResolveJsonSerializerNameReturnsDefaultWhenConfigMissing() 
{
+        Configuration configuration = mock(Configuration.class);
+        
when(configuration.getConfig(ConfigurationKeys.JSON_SERIALIZER_TYPE)).thenReturn(null);
+        
when(configuration.getConfig(ConfigurationKeys.TCC_BUSINESS_ACTION_CONTEXT_JSON_PARSER_NAME))
+                .thenReturn(null);
+
+        assertThat(JsonUtil.resolveJsonSerializerName(configuration))
+                .isEqualTo(DefaultValues.BUSINESS_ACTION_CONTEXT_JSON_PARSER);
+    }
+
+    @Test
+    public void 
testResolveJsonSerializerNameIgnoresBlankNewConfigAndFallsBackToDeprecatedConfig()
 {
+        Configuration configuration = mock(Configuration.class);
+        
when(configuration.getConfig(ConfigurationKeys.JSON_SERIALIZER_TYPE)).thenReturn("
 ");
+        
when(configuration.getConfig(ConfigurationKeys.TCC_BUSINESS_ACTION_CONTEXT_JSON_PARSER_NAME))
+                .thenReturn("fastjson2");
+
+        
assertThat(JsonUtil.resolveJsonSerializerName(configuration)).isEqualTo("fastjson2");
+    }
+
     public static class TestObject {
         private String name;
         private int value;
diff --git a/script/client/spring/application.properties 
b/script/client/spring/application.properties
index d640f9a567..a8ea24ce46 100755
--- a/script/client/spring/application.properties
+++ b/script/client/spring/application.properties
@@ -184,12 +184,13 @@ seata.registry.zk.password=
 
 seata.registry.custom.name=
 
+#You can choose from the following options: fastjson, fastjson2, jackson, 
jackson3, gson
+#Note: jackson3 is available only with JDK 17+ builds; otherwise Seata falls 
back to jackson.
+seata.json.serializer-type=jackson
 seata.json.allowlist=
 
 seata.tcc.fence.log-table-name=tcc_fence_log
 seata.tcc.fence.clean-period=1h
-#You can choose from the following options: fastjson, fastjson2, jackson, 
jackson3, gson
-seata.tcc.context-json-parser-type=fastjson
 
 
 seata.saga.enabled=false
diff --git a/script/client/spring/application.yml 
b/script/client/spring/application.yml
index f4cb02faaa..c1304dc756 100755
--- a/script/client/spring/application.yml
+++ b/script/client/spring/application.yml
@@ -201,13 +201,14 @@ seata:
   log:
     exception-rate: 100
   json:
+    # You can choose from the following options: fastjson, fastjson2, jackson, 
jackson3, gson
+    # Note: jackson3 is only available with JDK 17+ builds; otherwise Seata 
falls back to jackson
+    serializer-type: jackson
     allowlist: 
   tcc:
     fence:
       log-table-name: tcc_fence_log
       clean-period: 1h
-    # You can choose from the following options: fastjson, fastjson2, jackson, 
jackson3, gson
-    context-json-parser-type: fastjson
   saga:
     enabled: false
     state-machine:
diff --git 
a/seata-spring-autoconfigure/seata-spring-autoconfigure-client/src/main/java/org/apache/seata/spring/boot/autoconfigure/properties/SeataJsonProperties.java
 
b/seata-spring-autoconfigure/seata-spring-autoconfigure-client/src/main/java/org/apache/seata/spring/boot/autoconfigure/properties/SeataJsonProperties.java
index d7cc242de4..5554fa76d4 100644
--- 
a/seata-spring-autoconfigure/seata-spring-autoconfigure-client/src/main/java/org/apache/seata/spring/boot/autoconfigure/properties/SeataJsonProperties.java
+++ 
b/seata-spring-autoconfigure/seata-spring-autoconfigure-client/src/main/java/org/apache/seata/spring/boot/autoconfigure/properties/SeataJsonProperties.java
@@ -31,6 +31,16 @@ import static 
org.apache.seata.spring.boot.autoconfigure.StarterConstants.JSON_P
 @ConfigurationProperties(prefix = JSON_PREFIX)
 public class SeataJsonProperties {
 
+    /**
+     * JSON serializer implementation to use for Seata JSON 
serialization/deserialization.
+     * Supported values include fastjson, fastjson2, jackson, jackson3, and 
gson.
+     * The {@code jackson3} option requires JDK 17 or later; on lower JDK 
versions,
+     * Seata falls back to {@code jackson}.
+     * This property is bound from the Spring Boot configuration key {@code 
seata.json.serializer-type}
+     * (derived from {@code JSON_PREFIX}).
+     */
+    private String serializerType;
+
     /**
      * JSON deserialization allowlist, comma-separated
      * Entries ending with '.' are prefix matches, otherwise exact matches
@@ -38,6 +48,15 @@ public class SeataJsonProperties {
      */
     private String allowlist;
 
+    public String getSerializerType() {
+        return serializerType;
+    }
+
+    public SeataJsonProperties setSerializerType(String serializerType) {
+        this.serializerType = serializerType;
+        return this;
+    }
+
     public String getAllowlist() {
         return allowlist;
     }
diff --git 
a/seata-spring-autoconfigure/seata-spring-autoconfigure-client/src/main/java/org/apache/seata/spring/boot/autoconfigure/properties/SeataTccProperties.java
 
b/seata-spring-autoconfigure/seata-spring-autoconfigure-client/src/main/java/org/apache/seata/spring/boot/autoconfigure/properties/SeataTccProperties.java
index 473c6d5b67..efa31edc77 100644
--- 
a/seata-spring-autoconfigure/seata-spring-autoconfigure-client/src/main/java/org/apache/seata/spring/boot/autoconfigure/properties/SeataTccProperties.java
+++ 
b/seata-spring-autoconfigure/seata-spring-autoconfigure-client/src/main/java/org/apache/seata/spring/boot/autoconfigure/properties/SeataTccProperties.java
@@ -24,12 +24,24 @@ import static 
org.apache.seata.spring.boot.autoconfigure.StarterConstants.TCC_PR
 @Component
 @ConfigurationProperties(prefix = TCC_PREFIX)
 public class SeataTccProperties {
+    /**
+     * @deprecated Use {@code seata.json.serializer-type} / {@code 
json.serializerType} instead.
+     */
+    @Deprecated
     private String contextJsonParserType;
 
+    /**
+     * @deprecated Use {@code seata.json.serializer-type} / {@code 
json.serializerType} instead.
+     */
+    @Deprecated
     public String getContextJsonParserType() {
         return contextJsonParserType;
     }
 
+    /**
+     * @deprecated Use {@code seata.json.serializer-type} / {@code 
json.serializerType} instead.
+     */
+    @Deprecated
     public void setContextJsonParserType(String contextJsonParserType) {
         this.contextJsonParserType = contextJsonParserType;
     }
diff --git 
a/seata-spring-autoconfigure/seata-spring-autoconfigure-client/src/test/java/org/apache/seata/spring/boot/autoconfigure/properties/SeataJsonPropertiesTest.java
 
b/seata-spring-autoconfigure/seata-spring-autoconfigure-client/src/test/java/org/apache/seata/spring/boot/autoconfigure/properties/SeataJsonPropertiesTest.java
index 5ff2c27c8d..4a00340496 100644
--- 
a/seata-spring-autoconfigure/seata-spring-autoconfigure-client/src/test/java/org/apache/seata/spring/boot/autoconfigure/properties/SeataJsonPropertiesTest.java
+++ 
b/seata-spring-autoconfigure/seata-spring-autoconfigure-client/src/test/java/org/apache/seata/spring/boot/autoconfigure/properties/SeataJsonPropertiesTest.java
@@ -32,9 +32,12 @@ public class SeataJsonPropertiesTest {
     public void testSeataJsonProperties() {
         SeataJsonProperties props = new SeataJsonProperties();
 
+        String serializerType = "jackson";
         String allowlist = 
"com.test.model.,com.test.dto.,com.test.SpecialBean";
+        props.setSerializerType(serializerType);
         props.setAllowlist(allowlist);
 
+        Assertions.assertEquals(serializerType, props.getSerializerType());
         Assertions.assertEquals(allowlist, props.getAllowlist());
     }
 


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

Reply via email to