package com.liangjian.dataplatform.member.util;

import com.google.gson.Gson;

import java.lang.reflect.Type;

/**
 * @Author: 黄子奇
 * @Date: 2019/9/9 14:12
 *
 * 单例的Gson工具
 */
public class GsonUtil {
    private static GsonUtil ourInstance = null;

    private Gson gson;

    public static GsonUtil getInstance() {
        return ourInstance == null ? new GsonUtil() : ourInstance;
    }

    private GsonUtil() {
        this.gson = new Gson();
    }

    public String toJson(Object obj) {
        return this.gson.toJson(obj);
    }

    public <T> T fromJson(String json, Class<T> clazz) {
        return this.gson.fromJson(json,clazz);
    }

    public <T> T fromJson(String json, Type type) {
        return this.gson.fromJson(json,type);
    }
}
