불필요한 로직 제거 및 json 처리 메소드 이동
This commit is contained in:
@@ -12,6 +12,7 @@ import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
public class JSONUtils {
|
||||
@@ -19,6 +20,30 @@ public class JSONUtils {
|
||||
private JSONUtils() {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
public static Object parseJsonGeneric(Object jsonData) {
|
||||
if (jsonData == null) {
|
||||
return new JSONObject();
|
||||
}
|
||||
if (jsonData instanceof JSONObject) {
|
||||
return (JSONObject) jsonData;
|
||||
} else if (jsonData instanceof String) {
|
||||
if (StringUtils.isBlank((String) jsonData)) {
|
||||
return new JSONObject();
|
||||
}
|
||||
try {
|
||||
JSONParser parser = new JSONParser();
|
||||
Object parsedObj = parser.parse((String) jsonData);
|
||||
return parsedObj;
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
} else
|
||||
throw new IllegalArgumentException("not support json type. " + jsonData.getClass());
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static JSONObject parseJson(Object message) {
|
||||
if (message == null) {
|
||||
|
||||
Reference in New Issue
Block a user