package com.brilliance.isc.swift.objmtconvert.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.google.gson.Gson;

import java.util.Map;

/**
 * @author gechengyang
 * @date 2023/2/17
 */
public class JsonUtil {

    public static JSONObject getJsonObj(String json) {
        JSONObject jsonObject = JSON.parseObject(json);
        return jsonObject;
    }

    public static Map json2Map(String json) {
//        Map<String, Object> map = JSONObject.parseObject(json, new TypeReference<Map<String, Object>>() {
//        });
        Map<String, Object> map = new Gson().fromJson(json,Map.class);
        return map;
    }

    public static String toJson(Object obj) {
        return JSON.toJSONString(obj);
    }

    public static <T> T deepCopy(T data, Class<T> tClass){
        T bakData = JSONObject.parseObject((String) data).toJavaObject(tClass);
        return bakData;
    }
}
