Skip to content

Commit

Permalink
use static method in static class JSON (#2156)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrywu committed Mar 13, 2020
1 parent dd2c50a commit daad5ef
Show file tree
Hide file tree
Showing 19 changed files with 79 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
*/
package org.apache.dolphinscheduler.alert.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.dolphinscheduler.common.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -38,7 +38,7 @@ public class JSONUtils {
*/
public static String toJsonString(Object object) {
try{
return JSONObject.toJSONString(object,false);
return JSON.toJSONString(object,false);
} catch (Exception e) {
throw new RuntimeException("Json deserialization exception.", e);
}
Expand All @@ -57,7 +57,7 @@ public static <T> List<T> toList(String json, Class<T> clazz) {
return null;
}
try {
return JSONArray.parseArray(json, clazz);
return JSON.parseArray(json, clazz);
} catch (Exception e) {
logger.error("JSONArray.parseArray exception!",e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.dolphinscheduler.api.service;

import com.alibaba.fastjson.JSON;
import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.utils.PageInfo;
import org.apache.dolphinscheduler.api.utils.Result;
Expand Down Expand Up @@ -303,7 +304,7 @@ private void handlePasswd(List<DataSource> dataSourceList) {
for (DataSource dataSource : dataSourceList) {

String connectionParams = dataSource.getConnectionParams();
JSONObject object = JSONObject.parseObject(connectionParams);
JSONObject object = JSON.parseObject(connectionParams);
object.put(Constants.PASSWORD, Constants.XXXXXX);
dataSource.setConnectionParams(JSONUtils.toJson(object));

Expand Down Expand Up @@ -367,11 +368,11 @@ private Connection getConnection(DbType dbType, String parameter) {
try {
switch (dbType) {
case POSTGRESQL:
datasource = JSONObject.parseObject(parameter, PostgreDataSource.class);
datasource = JSON.parseObject(parameter, PostgreDataSource.class);
Class.forName(Constants.ORG_POSTGRESQL_DRIVER);
break;
case MYSQL:
datasource = JSONObject.parseObject(parameter, MySQLDataSource.class);
datasource = JSON.parseObject(parameter, MySQLDataSource.class);
Class.forName(Constants.COM_MYSQL_JDBC_DRIVER);
break;
case HIVE:
Expand All @@ -386,26 +387,26 @@ private Connection getConnection(DbType dbType, String parameter) {
getString(org.apache.dolphinscheduler.common.Constants.LOGIN_USER_KEY_TAB_PATH));
}
if (dbType == DbType.HIVE){
datasource = JSONObject.parseObject(parameter, HiveDataSource.class);
datasource = JSON.parseObject(parameter, HiveDataSource.class);
}else if (dbType == DbType.SPARK){
datasource = JSONObject.parseObject(parameter, SparkDataSource.class);
datasource = JSON.parseObject(parameter, SparkDataSource.class);
}
Class.forName(Constants.ORG_APACHE_HIVE_JDBC_HIVE_DRIVER);
break;
case CLICKHOUSE:
datasource = JSONObject.parseObject(parameter, ClickHouseDataSource.class);
datasource = JSON.parseObject(parameter, ClickHouseDataSource.class);
Class.forName(Constants.COM_CLICKHOUSE_JDBC_DRIVER);
break;
case ORACLE:
datasource = JSONObject.parseObject(parameter, OracleDataSource.class);
datasource = JSON.parseObject(parameter, OracleDataSource.class);
Class.forName(Constants.COM_ORACLE_JDBC_DRIVER);
break;
case SQLSERVER:
datasource = JSONObject.parseObject(parameter, SQLServerDataSource.class);
datasource = JSON.parseObject(parameter, SQLServerDataSource.class);
Class.forName(Constants.COM_SQLSERVER_JDBC_DRIVER);
break;
case DB2:
datasource = JSONObject.parseObject(parameter, DB2ServerDataSource.class);
datasource = JSON.parseObject(parameter, DB2ServerDataSource.class);
Class.forName(Constants.COM_DB2_JDBC_DRIVER);
break;
default:
Expand Down Expand Up @@ -507,7 +508,7 @@ public String buildParameter(String name, String desc, DbType type, String host,
parameterMap.put(Constants.PRINCIPAL,principal);
}
if (other != null && !"".equals(other)) {
LinkedHashMap<String, String> map = JSONObject.parseObject(other, new TypeReference<LinkedHashMap<String, String>>() {
LinkedHashMap<String, String> map = JSON.parseObject(other, new TypeReference<LinkedHashMap<String, String>>() {
});
if (map.size() > 0) {
StringBuilder otherSb = new StringBuilder();
Expand All @@ -523,9 +524,9 @@ public String buildParameter(String name, String desc, DbType type, String host,
}

if(logger.isDebugEnabled()){
logger.info("parameters map-----" + JSONObject.toJSONString(parameterMap));
logger.info("parameters map-----" + JSON.toJSONString(parameterMap));
}
return JSONObject.toJSONString(parameterMap);
return JSON.toJSONString(parameterMap);


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.dolphinscheduler.api.controller;

import com.alibaba.fastjson.JSON;
import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.enums.ResourceType;
Expand Down Expand Up @@ -54,7 +55,7 @@ public void testQuerytResourceList() throws Exception {

Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
result.getCode().equals(Status.SUCCESS.getCode());
JSONObject object = (JSONObject) JSONObject.parse(mvcResult.getResponse().getContentAsString());
JSONObject object = (JSONObject) JSON.parse(mvcResult.getResponse().getContentAsString());

Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
logger.info(mvcResult.getResponse().getContentAsString());
Expand All @@ -78,7 +79,7 @@ public void testQueryResourceListPaging() throws Exception {

Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
result.getCode().equals(Status.SUCCESS.getCode());
JSONObject object = (JSONObject) JSONObject.parse(mvcResult.getResponse().getContentAsString());
JSONObject object = (JSONObject) JSON.parse(mvcResult.getResponse().getContentAsString());

Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
logger.info(mvcResult.getResponse().getContentAsString());
Expand Down Expand Up @@ -281,7 +282,7 @@ public void testQueryUdfFuncList() throws Exception {

Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
result.getCode().equals(Status.SUCCESS.getCode());
JSONObject object = (JSONObject) JSONObject.parse(mvcResult.getResponse().getContentAsString());
JSONObject object = (JSONObject) JSON.parse(mvcResult.getResponse().getContentAsString());

Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
logger.info(mvcResult.getResponse().getContentAsString());
Expand All @@ -303,7 +304,7 @@ public void testQueryResourceList() throws Exception {

Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
result.getCode().equals(Status.SUCCESS.getCode());
JSONObject object = (JSONObject) JSONObject.parse(mvcResult.getResponse().getContentAsString());
JSONObject object = (JSONObject) JSON.parse(mvcResult.getResponse().getContentAsString());

Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
logger.info(mvcResult.getResponse().getContentAsString());
Expand All @@ -324,7 +325,7 @@ public void testVerifyUdfFuncName() throws Exception {

Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
result.getCode().equals(Status.SUCCESS.getCode());
JSONObject object = (JSONObject) JSONObject.parse(mvcResult.getResponse().getContentAsString());
JSONObject object = (JSONObject) JSON.parse(mvcResult.getResponse().getContentAsString());

Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
logger.info(mvcResult.getResponse().getContentAsString());
Expand All @@ -344,7 +345,7 @@ public void testAuthorizedFile() throws Exception {

Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
result.getCode().equals(Status.SUCCESS.getCode());
JSONObject object = (JSONObject) JSONObject.parse(mvcResult.getResponse().getContentAsString());
JSONObject object = (JSONObject) JSON.parse(mvcResult.getResponse().getContentAsString());

Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
logger.info(mvcResult.getResponse().getContentAsString());
Expand All @@ -365,7 +366,7 @@ public void testUnauthorizedFile() throws Exception {

Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
result.getCode().equals(Status.SUCCESS.getCode());
JSONObject object = (JSONObject) JSONObject.parse(mvcResult.getResponse().getContentAsString());
JSONObject object = (JSONObject) JSON.parse(mvcResult.getResponse().getContentAsString());

Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
logger.info(mvcResult.getResponse().getContentAsString());
Expand All @@ -386,7 +387,7 @@ public void testAuthorizedUDFFunction() throws Exception {

Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
result.getCode().equals(Status.SUCCESS.getCode());
JSONObject object = (JSONObject) JSONObject.parse(mvcResult.getResponse().getContentAsString());
JSONObject object = (JSONObject) JSON.parse(mvcResult.getResponse().getContentAsString());

Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
logger.info(mvcResult.getResponse().getContentAsString());
Expand All @@ -406,7 +407,7 @@ public void testUnauthUDFFunc() throws Exception {

Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
result.getCode().equals(Status.SUCCESS.getCode());
JSONObject object = (JSONObject) JSONObject.parse(mvcResult.getResponse().getContentAsString());
JSONObject object = (JSONObject) JSON.parse(mvcResult.getResponse().getContentAsString());

Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
logger.info(mvcResult.getResponse().getContentAsString());
Expand All @@ -427,7 +428,7 @@ public void testDeleteUdfFunc() throws Exception {

Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
result.getCode().equals(Status.SUCCESS.getCode());
JSONObject object = (JSONObject) JSONObject.parse(mvcResult.getResponse().getContentAsString());
JSONObject object = (JSONObject) JSON.parse(mvcResult.getResponse().getContentAsString());

Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
logger.info(mvcResult.getResponse().getContentAsString());
Expand All @@ -446,7 +447,7 @@ public void testDeleteResource() throws Exception {

Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
result.getCode().equals(Status.SUCCESS.getCode());
JSONObject object = (JSONObject) JSONObject.parse(mvcResult.getResponse().getContentAsString());
JSONObject object = (JSONObject) JSON.parse(mvcResult.getResponse().getContentAsString());

Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
logger.info(mvcResult.getResponse().getContentAsString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
*/
package org.apache.dolphinscheduler.common.model;

import com.alibaba.fastjson.JSON;
import org.apache.dolphinscheduler.common.Constants;
import org.apache.dolphinscheduler.common.enums.Priority;
import org.apache.dolphinscheduler.common.enums.TaskTimeoutStrategy;
import org.apache.dolphinscheduler.common.enums.TaskType;
import org.apache.dolphinscheduler.common.task.TaskTimeoutParameter;
import org.apache.dolphinscheduler.common.utils.CollectionUtils;
import org.apache.dolphinscheduler.common.utils.JSONUtils;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
Expand Down Expand Up @@ -294,7 +294,7 @@ public TaskTimeoutParameter getTaskTimeoutParameter() {
if(StringUtils.isNotEmpty(this.getTimeout())){
String formatStr = String.format("%s,%s", TaskTimeoutStrategy.WARN.name(), TaskTimeoutStrategy.FAILED.name());
String timeout = this.getTimeout().replace(formatStr,TaskTimeoutStrategy.WARNFAILED.name());
return JSONObject.parseObject(timeout,TaskTimeoutParameter.class);
return JSON.parseObject(timeout,TaskTimeoutParameter.class);
}
return new TaskTimeoutParameter(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.dolphinscheduler.common.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
Expand Down Expand Up @@ -59,7 +60,7 @@ private JSONUtils() {
*/
public static String toJson(Object object) {
try{
return JSONObject.toJSONString(object,false);
return JSON.toJSONString(object,false);
} catch (Exception e) {
logger.error("object to json exception!",e);
}
Expand Down Expand Up @@ -89,7 +90,7 @@ public static <T> T parseObject(String json, Class<T> clazz) {
}

try {
return JSONObject.parseObject(json, clazz);
return JSON.parseObject(json, clazz);
} catch (Exception e) {
logger.error("parse object exception!",e);
}
Expand Down Expand Up @@ -178,7 +179,7 @@ public static Map<String, String> toMap(String json) {
}

try {
return JSONObject.parseObject(json, new TypeReference<HashMap<String, String>>(){});
return JSON.parseObject(json, new TypeReference<HashMap<String, String>>(){});
} catch (Exception e) {
logger.error("json to map exception!",e);
}
Expand All @@ -203,7 +204,7 @@ public static <K, V> Map<K, V> toMap(String json, Class<K> classK, Class<V> clas
}

try {
return JSONObject.parseObject(json, new TypeReference<HashMap<K, V>>() {});
return JSON.parseObject(json, new TypeReference<HashMap<K, V>>() {});
} catch (Exception e) {
logger.error("json to map exception!",e);
}
Expand All @@ -218,23 +219,23 @@ public static <K, V> Map<K, V> toMap(String json, Class<K> classK, Class<V> clas
*/
public static String toJsonString(Object object) {
try{
return JSONObject.toJSONString(object,false);
return JSON.toJSONString(object,false);
} catch (Exception e) {
throw new RuntimeException("Json deserialization exception.", e);
}
}

public static JSONObject parseObject(String text) {
try{
return JSONObject.parseObject(text);
return JSON.parseObject(text);
} catch (Exception e) {
throw new RuntimeException("Json deserialization exception.", e);
}
}

public static JSONArray parseArray(String text) {
try{
return JSONObject.parseArray(text);
return JSON.parseArray(text);
} catch (Exception e) {
throw new RuntimeException("Json deserialization exception.", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
*/
package org.apache.dolphinscheduler.common.utils;

import com.alibaba.fastjson.JSON;
import org.apache.dolphinscheduler.common.Constants;
import org.apache.dolphinscheduler.common.enums.CommandType;
import org.apache.dolphinscheduler.common.enums.DataType;
import org.apache.dolphinscheduler.common.process.Property;
import org.apache.dolphinscheduler.common.utils.placeholder.BusinessTimeUtils;
import org.apache.dolphinscheduler.common.utils.placeholder.PlaceholderUtils;
import org.apache.dolphinscheduler.common.utils.placeholder.TimePlaceholderUtils;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateUtils;
import org.slf4j.Logger;
Expand Down Expand Up @@ -157,7 +157,7 @@ public static String curingGlobalParams(Map<String,String> globalParamMap, List<
property.setValue(val);
}
}
return JSONObject.toJSONString(globalParamList);
return JSON.toJSONString(globalParamList);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
*/
package org.apache.dolphinscheduler.common.utils;

import com.alibaba.fastjson.JSON;
import org.apache.dolphinscheduler.common.enums.DataType;
import org.apache.dolphinscheduler.common.enums.Direct;
import org.apache.dolphinscheduler.common.process.Property;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import org.junit.Assert;
Expand Down Expand Up @@ -53,7 +53,7 @@ public void convert2Property(){
property.setType(DataType.VARCHAR);
property.setValue("sssssss");
String str = "{\"direct\":\"IN\",\"prop\":\"ds\",\"type\":\"VARCHAR\",\"value\":\"sssssss\"}";
Property property1 = JSONObject.parseObject(str, Property.class);
Property property1 = JSON.parseObject(str, Property.class);
Direct direct = property1.getDirect();
Assert.assertEquals(direct , Direct.IN);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
package org.apache.dolphinscheduler.common.utils;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSON;
import org.apache.commons.lang.time.DateUtils;
import org.apache.dolphinscheduler.common.enums.CommandType;
import org.apache.dolphinscheduler.common.enums.DataType;
Expand Down Expand Up @@ -91,13 +91,13 @@ public void testCuringGlobalParams() throws Exception {
globalParamList.add(property);

String result2 = ParameterUtils.curingGlobalParams(null,globalParamList,CommandType.START_CURRENT_TASK_PROCESS,scheduleTime);
Assert.assertEquals(result2, JSONObject.toJSONString(globalParamList));
Assert.assertEquals(result2, JSON.toJSONString(globalParamList));

String result3 = ParameterUtils.curingGlobalParams(globalParamMap,globalParamList,CommandType.START_CURRENT_TASK_PROCESS,null);
Assert.assertEquals(result3, JSONObject.toJSONString(globalParamList));
Assert.assertEquals(result3, JSON.toJSONString(globalParamList));

String result4 = ParameterUtils.curingGlobalParams(globalParamMap, globalParamList, CommandType.START_CURRENT_TASK_PROCESS, scheduleTime);
Assert.assertEquals(result4, JSONObject.toJSONString(globalParamList));
Assert.assertEquals(result4, JSON.toJSONString(globalParamList));

//test var $ startsWith
globalParamMap.put("bizDate","${system.biz.date}");
Expand Down
Loading

0 comments on commit daad5ef

Please sign in to comment.