com.suyeer.basic.util.JsonUtil Maven / Gradle / Ivy
package com.suyeer.basic.util;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import java.lang.reflect.Type;
import java.util.List;
/**
* @author jun 2018/10/19
*/
public class JsonUtil {
public static String toString(Object obj) {
return JSON.toJSONString(obj);
}
public static T clone(Object srcObj, Type classOfT) {
return JSON.parseObject(JsonUtil.toString(srcObj), classOfT);
}
public static T changeType(Object srcObj, Type tagClass) {
return JsonUtil.clone(srcObj, tagClass);
}
public static List parseArray(Object srcObj, Class clazz) {
return JSON.parseArray(JsonUtil.toString(srcObj), clazz);
}
public static JSONObject toJSONObject(Object srcObj) {
return JSON.parseObject(toString(srcObj));
}
public static JSONArray parseArray(Object srcObj) {
return JSON.parseArray(JsonUtil.toString(srcObj));
}
public static String[] toStringArr(JSONArray jsonArr) {
return jsonArr.toArray(new String[jsonArr.size()]);
}
public static Integer[] toIntegerArr(JSONArray jsonArr) {
return jsonArr.toArray(new Integer[jsonArr.size()]);
}
}