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

wenjun pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git


The following commit(s) were added to refs/heads/dev by this push:
     new 4625783  [Fix-6072][common] Remove Generic method JsonUtils.toMap 
(#6283)
4625783 is described below

commit 46257834792d3316c9f5ef885f38e069e4eb6452
Author: HanayoZz <[email protected]>
AuthorDate: Thu Sep 23 11:06:53 2021 -0400

    [Fix-6072][common] Remove Generic method JsonUtils.toMap (#6283)
    
    * [Fix][common] Remove Generic method JsonUtils.toMap, Replace by 
parseObj(String json, TypeReference type)
---
 .../api/service/impl/ExecutorServiceImpl.java              |  3 ++-
 .../org/apache/dolphinscheduler/common/model/TaskNode.java |  6 ++++--
 .../apache/dolphinscheduler/common/utils/JSONUtils.java    | 14 --------------
 .../dolphinscheduler/common/utils/JSONUtilsTest.java       |  2 --
 .../apache/dolphinscheduler/dao/entity/TaskInstance.java   |  7 ++++---
 .../dolphinscheduler/service/process/ProcessService.java   |  2 +-
 6 files changed, 11 insertions(+), 23 deletions(-)

diff --git 
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ExecutorServiceImpl.java
 
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ExecutorServiceImpl.java
index 7459885..eb0f39e 100644
--- 
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ExecutorServiceImpl.java
+++ 
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ExecutorServiceImpl.java
@@ -24,6 +24,7 @@ import static 
org.apache.dolphinscheduler.common.Constants.CMD_PARAM_START_NODE_
 import static 
org.apache.dolphinscheduler.common.Constants.CMD_PARAM_START_PARAMS;
 import static org.apache.dolphinscheduler.common.Constants.MAX_TASK_TIMEOUT;
 
+import com.fasterxml.jackson.core.type.TypeReference;
 import org.apache.dolphinscheduler.api.enums.ExecuteType;
 import org.apache.dolphinscheduler.api.enums.Status;
 import org.apache.dolphinscheduler.api.service.ExecutorService;
@@ -270,7 +271,7 @@ public class ExecutorServiceImpl extends BaseServiceImpl 
implements ExecutorServ
         }
 
         //get the startParams user specified at the first starting while 
repeat running is needed
-        Map<String, Object> commandMap = 
JSONUtils.toMap(processInstance.getCommandParam(), String.class, Object.class);
+        Map<String, Object> commandMap = 
JSONUtils.parseObject(processInstance.getCommandParam(), new 
TypeReference<Map<String, Object>>() {});
         String startParams = null;
         if (MapUtils.isNotEmpty(commandMap) && executeType == 
ExecuteType.REPEAT_RUNNING) {
             Object startParamsJson = 
commandMap.get(Constants.CMD_PARAM_START_PARAMS);
diff --git 
a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/model/TaskNode.java
 
b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/model/TaskNode.java
index e971263..d963abe 100644
--- 
a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/model/TaskNode.java
+++ 
b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/model/TaskNode.java
@@ -17,6 +17,7 @@
 
 package org.apache.dolphinscheduler.common.model;
 
+import com.fasterxml.jackson.core.type.TypeReference;
 import org.apache.dolphinscheduler.common.Constants;
 import org.apache.dolphinscheduler.common.enums.Priority;
 import org.apache.dolphinscheduler.common.enums.TaskTimeoutStrategy;
@@ -393,7 +394,8 @@ public class TaskNode {
     }
 
     public String getTaskParams() {
-        Map<String, Object> taskParams = JSONUtils.toMap(this.params, 
String.class, Object.class);
+        Map<String, Object> taskParams = JSONUtils.parseObject(this.params, 
new TypeReference<Map<String, Object>>() {});
+
         if (taskParams == null) {
             taskParams = new HashMap<>();
         }
@@ -405,7 +407,7 @@ public class TaskNode {
     }
 
     public Map<String, Object> taskParamsToJsonObj(String taskParams) {
-        Map<String, Object> taskParamsMap = JSONUtils.toMap(taskParams, 
String.class, Object.class);
+        Map<String, Object> taskParamsMap = JSONUtils.parseObject(taskParams, 
new TypeReference<Map<String, Object>>() {});
         if (taskParamsMap == null) {
             taskParamsMap = new HashMap<>();
         }
diff --git 
a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/JSONUtils.java
 
b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/JSONUtils.java
index 09f4432..92da8fc 100644
--- 
a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/JSONUtils.java
+++ 
b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/JSONUtils.java
@@ -236,20 +236,6 @@ public class JSONUtils {
             return "";
         }
     }
-    
-    /**
-     * json to map
-     *
-     * @param json json
-     * @param classK classK
-     * @param classV classV
-     * @param <K> K
-     * @param <V> V
-     * @return to map
-     */
-    public static <K, V> Map<K, V> toMap(String json, Class<K> classK, 
Class<V> classV) {
-        return parseObject(json, new TypeReference<Map<K, V>>() {});
-    }
 
     /**
      * json to object
diff --git 
a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/JSONUtilsTest.java
 
b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/JSONUtilsTest.java
index d9398f8..786fb76 100644
--- 
a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/JSONUtilsTest.java
+++ 
b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/JSONUtilsTest.java
@@ -199,8 +199,6 @@ public class JSONUtilsTest {
 
         Assert.assertNull(JSONUtils.toMap("3"));
         Assert.assertNull(JSONUtils.toMap(null));
-        Assert.assertNull(JSONUtils.toMap("3", null, null));
-        Assert.assertNull(JSONUtils.toMap(null, null, null));
 
         String str = 
"{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"#!/bin/bash\\necho 
\\\"shell-1\\\"\"}";
         Map<String, String> m = JSONUtils.toMap(str);
diff --git 
a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/TaskInstance.java
 
b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/TaskInstance.java
index 47c6082..7948df4 100644
--- 
a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/TaskInstance.java
+++ 
b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/TaskInstance.java
@@ -17,6 +17,7 @@
 
 package org.apache.dolphinscheduler.dao.entity;
 
+import com.fasterxml.jackson.core.type.TypeReference;
 import org.apache.dolphinscheduler.common.Constants;
 import org.apache.dolphinscheduler.common.enums.ExecutionStatus;
 import org.apache.dolphinscheduler.common.enums.Flag;
@@ -448,7 +449,7 @@ public class TaskInstance implements Serializable {
 
     public DependentParameters getDependency() {
         if (this.dependency == null) {
-            Map<String, Object> taskParamsMap = 
JSONUtils.toMap(this.getTaskParams(), String.class, Object.class);
+            Map<String, Object> taskParamsMap = 
JSONUtils.parseObject(this.getTaskParams(), new TypeReference<Map<String, 
Object>>() {});
             this.dependency = JSONUtils.parseObject((String) 
taskParamsMap.get(Constants.DEPENDENCE), DependentParameters.class);
         }
         return this.dependency;
@@ -460,14 +461,14 @@ public class TaskInstance implements Serializable {
 
     public SwitchParameters getSwitchDependency() {
         if (this.switchDependency == null) {
-            Map<String, Object> taskParamsMap = 
JSONUtils.toMap(this.getTaskParams(), String.class, Object.class);
+            Map<String, Object> taskParamsMap = 
JSONUtils.parseObject(this.getTaskParams(), new TypeReference<Map<String, 
Object>>() {});
             this.switchDependency = JSONUtils.parseObject((String) 
taskParamsMap.get(Constants.SWITCH_RESULT), SwitchParameters.class);
         }
         return this.switchDependency;
     }
 
     public void setSwitchDependency(SwitchParameters switchDependency) {
-        Map<String, Object> taskParamsMap = 
JSONUtils.toMap(this.getTaskParams(), String.class, Object.class);
+        Map<String, Object> taskParamsMap = 
JSONUtils.parseObject(this.getTaskParams(), new TypeReference<Map<String, 
Object>>() {});
         
taskParamsMap.put(Constants.SWITCH_RESULT,JSONUtils.toJsonString(switchDependency));
         this.setTaskParams(JSONUtils.toJsonString(taskParamsMap));
     }
diff --git 
a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java
 
b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java
index dca69ff..bf4f6f7 100644
--- 
a/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java
+++ 
b/dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/process/ProcessService.java
@@ -1779,7 +1779,7 @@ public class ProcessService {
             return;
         }
         //if the result more than one line,just get the first .
-        Map<String, Object> taskParams = 
JSONUtils.toMap(taskInstance.getTaskParams(), String.class, Object.class);
+        Map<String, Object> taskParams = 
JSONUtils.parseObject(taskInstance.getTaskParams(), new 
TypeReference<Map<String, Object>>() {});
         Object localParams = taskParams.get(LOCAL_PARAMS);
         if (localParams == null) {
             return;

Reply via email to