All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.suyeer.basic.util.JsonUtil Maven / Gradle / Ivy

There is a newer version: 6.0.1
Show newest version
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()]);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy