AE86 2 ani în urmă
părinte
comite
70a9a4c757

+ 12 - 18
dbsyncer-biz/src/main/java/org/dbsyncer/biz/checker/AbstractChecker.java

@@ -1,6 +1,8 @@
 package org.dbsyncer.biz.checker;
 
-import org.dbsyncer.biz.BizException;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import org.dbsyncer.common.snowflake.SnowflakeIdWorker;
 import org.dbsyncer.common.util.CollectionUtils;
 import org.dbsyncer.common.util.JsonUtil;
 import org.dbsyncer.common.util.StringUtil;
@@ -10,11 +12,7 @@ import org.dbsyncer.parser.model.AbstractConfigModel;
 import org.dbsyncer.parser.model.ConfigModel;
 import org.dbsyncer.parser.model.Convert;
 import org.dbsyncer.plugin.config.Plugin;
-import org.dbsyncer.common.snowflake.SnowflakeIdWorker;
 import org.dbsyncer.storage.constant.ConfigConstant;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.util.Assert;
 
@@ -99,20 +97,16 @@ public abstract class AbstractChecker implements Checker {
     }
 
     private <T> List<T> jsonToList(String json, Class<T> valueType) {
-        try {
-            JSONArray array = new JSONArray(json);
-            if (null != array) {
-                List<T> list = new ArrayList<>();
-                int length = array.length();
-                for (int i = 0; i < length; i++) {
-                    JSONObject obj = array.getJSONObject(i);
-                    T t = JsonUtil.jsonToObj(obj.toString(), valueType);
-                    list.add(t);
-                }
-                return list;
+        JSONArray array = JsonUtil.parseArray(json);
+        if (null != array) {
+            List<T> list = new ArrayList<>();
+            int length = array.size();
+            for (int i = 0; i < length; i++) {
+                JSONObject obj = array.getJSONObject(i);
+                T t = JsonUtil.jsonToObj(obj.toString(), valueType);
+                list.add(t);
             }
-        } catch (JSONException e) {
-            throw new BizException(String.format("解析高级配置参数异常:%s", json));
+            return list;
         }
         return Collections.EMPTY_LIST;
     }

+ 25 - 30
dbsyncer-biz/src/main/java/org/dbsyncer/biz/checker/impl/tablegroup/TableGroupChecker.java

@@ -1,9 +1,12 @@
 package org.dbsyncer.biz.checker.impl.tablegroup;
 
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import org.dbsyncer.biz.BizException;
 import org.dbsyncer.biz.checker.AbstractChecker;
 import org.dbsyncer.biz.checker.ConnectorConfigChecker;
 import org.dbsyncer.common.util.CollectionUtils;
+import org.dbsyncer.common.util.JsonUtil;
 import org.dbsyncer.common.util.StringUtil;
 import org.dbsyncer.connector.model.Field;
 import org.dbsyncer.connector.model.MetaInfo;
@@ -16,9 +19,6 @@ import org.dbsyncer.parser.model.Mapping;
 import org.dbsyncer.parser.model.TableGroup;
 import org.dbsyncer.parser.util.PickerUtil;
 import org.dbsyncer.storage.constant.ConfigConstant;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -190,37 +190,32 @@ public class TableGroupChecker extends AbstractChecker {
      * @return
      */
     private void setFieldMapping(TableGroup tableGroup, String json) {
-        try {
-            JSONArray mapping = new JSONArray(json);
-            if (null == mapping) {
-                throw new BizException("映射关系不能为空");
-            }
+        JSONArray mapping = JsonUtil.parseArray(json);
+        if (null == mapping) {
+            throw new BizException("映射关系不能为空");
+        }
 
-            final Map<String, Field> sMap = PickerUtil.convert2Map(tableGroup.getSourceTable().getColumn());
-            final Map<String, Field> tMap = PickerUtil.convert2Map(tableGroup.getTargetTable().getColumn());
-            int length = mapping.length();
-            List<FieldMapping> list = new ArrayList<>();
-            JSONObject row = null;
-            Field s = null;
-            Field t = null;
-            for (int i = 0; i < length; i++) {
-                row = mapping.getJSONObject(i);
-                s = sMap.get(row.getString("source"));
-                t = tMap.get(row.getString("target"));
-                if (null == s && null == t) {
-                    continue;
-                }
+        final Map<String, Field> sMap = PickerUtil.convert2Map(tableGroup.getSourceTable().getColumn());
+        final Map<String, Field> tMap = PickerUtil.convert2Map(tableGroup.getTargetTable().getColumn());
+        int length = mapping.size();
+        List<FieldMapping> list = new ArrayList<>();
+        JSONObject row = null;
+        Field s = null;
+        Field t = null;
+        for (int i = 0; i < length; i++) {
+            row = mapping.getJSONObject(i);
+            s = sMap.get(row.getString("source"));
+            t = tMap.get(row.getString("target"));
+            if (null == s && null == t) {
+                continue;
+            }
 
-                if (null != t) {
-                    t.setPk(row.getBoolean("pk"));
-                }
-                list.add(new FieldMapping(s, t));
+            if (null != t) {
+                t.setPk(row.getBoolean("pk"));
             }
-            tableGroup.setFieldMapping(list);
-        } catch (JSONException e) {
-            logger.error(e.getMessage());
-            throw new BizException(e.getMessage());
+            list.add(new FieldMapping(s, t));
         }
+        tableGroup.setFieldMapping(list);
     }
 
 }

+ 0 - 5
dbsyncer-common/pom.xml

@@ -55,11 +55,6 @@
             <artifactId>commons-io</artifactId>
         </dependency>
 
-        <!-- json -->
-        <dependency>
-            <groupId>org.json</groupId>
-            <artifactId>json</artifactId>
-        </dependency>
         <!-- fastjson -->
         <dependency>
             <groupId>com.alibaba</groupId>

+ 9 - 0
dbsyncer-common/src/main/java/org/dbsyncer/common/util/JsonUtil.java

@@ -1,6 +1,8 @@
 package org.dbsyncer.common.util;
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.serializer.SerializerFeature;
 
 import java.util.List;
@@ -19,4 +21,11 @@ public abstract class JsonUtil {
         return JSON.parseArray(json, valueType);
     }
 
+    public static JSONObject parseObject(String json) {
+        return JSON.parseObject(json);
+    }
+
+    public static JSONArray parseArray(String json) {
+        return JSON.parseArray(json);
+    }
 }

+ 3 - 3
dbsyncer-parser/src/main/java/org/dbsyncer/parser/ParserFactory.java

@@ -1,5 +1,7 @@
 package org.dbsyncer.parser;
 
+import com.alibaba.fastjson.JSONException;
+import com.alibaba.fastjson.JSONObject;
 import org.dbsyncer.cache.CacheService;
 import org.dbsyncer.common.event.RowChangedEvent;
 import org.dbsyncer.common.model.Result;
@@ -30,8 +32,6 @@ import org.dbsyncer.parser.util.ConvertUtil;
 import org.dbsyncer.parser.util.PickerUtil;
 import org.dbsyncer.plugin.PluginFactory;
 import org.dbsyncer.storage.enums.StorageDataStatusEnum;
-import org.json.JSONException;
-import org.json.JSONObject;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -174,7 +174,7 @@ public class ParserFactory implements Parser {
     @Override
     public Connector parseConnector(String json) {
         try {
-            JSONObject conn = new JSONObject(json);
+            JSONObject conn = JsonUtil.parseObject(json);
             JSONObject config = (JSONObject) conn.remove("config");
             Connector connector = JsonUtil.jsonToObj(conn.toString(), Connector.class);
             Assert.notNull(connector, "Connector can not be null.");

+ 5 - 7
dbsyncer-parser/src/main/test/ConnectorParserTest.java

@@ -1,5 +1,5 @@
-package org.dbsyncer.parser;
-
+import com.alibaba.fastjson.JSONException;
+import com.alibaba.fastjson.JSONObject;
 import org.apache.commons.io.FileUtils;
 import org.dbsyncer.common.util.JsonUtil;
 import org.dbsyncer.connector.config.ConnectorConfig;
@@ -7,8 +7,6 @@ import org.dbsyncer.connector.enums.ConnectorEnum;
 import org.dbsyncer.parser.model.Connector;
 import org.dbsyncer.parser.model.Mapping;
 import org.dbsyncer.parser.model.TableGroup;
-import org.json.JSONException;
-import org.json.JSONObject;
 import org.junit.Test;
 
 import java.io.File;
@@ -28,7 +26,7 @@ public class ConnectorParserTest {
         System.out.println(json);
 
         // 解析基本信息
-        JSONObject conn = new JSONObject(json);
+        JSONObject conn = JsonUtil.parseObject(json);
         JSONObject config = (JSONObject) conn.remove("config");
         Connector connector = JsonUtil.jsonToObj(conn.toString(), Connector.class);
 
@@ -46,7 +44,7 @@ public class ConnectorParserTest {
         System.out.println(json);
 
         // 解析基本信息
-        JSONObject map = new JSONObject(json);
+        JSONObject map = JsonUtil.parseObject(json);
         Mapping mapping = JsonUtil.jsonToObj(map.toString(), Mapping.class);
         System.out.println(mapping);
     }
@@ -56,7 +54,7 @@ public class ConnectorParserTest {
         String json = readJson("TableGroup.json");
         System.out.println(json);
         // 解析基本信息
-        JSONObject group = new JSONObject(json);
+        JSONObject group = JsonUtil.parseObject(json);
         TableGroup tableGroup = JsonUtil.jsonToObj(group.toString(), TableGroup.class);
         System.out.println(tableGroup);
     }

+ 0 - 7
pom.xml

@@ -48,7 +48,6 @@
         <mssql-jdbc.version>7.4.1.jre8</mssql-jdbc.version>
         <postgresql.version>42.3.3</postgresql.version>
         <kafka.version>0.9.0.0</kafka.version>
-        <json.version>20090211</json.version>
         <fastjson.version>1.2.75</fastjson.version>
         <protobuf.version>3.21.1</protobuf.version>
         <log4j2.version>2.17.1</log4j2.version>
@@ -113,12 +112,6 @@
                 <version>${commons-io.version}</version>
             </dependency>
 
-            <!-- json -->
-            <dependency>
-                <groupId>org.json</groupId>
-                <artifactId>json</artifactId>
-                <version>${json.version}</version>
-            </dependency>
             <!-- fastjson -->
             <dependency>
                 <groupId>com.alibaba</groupId>