package dev.other;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import java.io.StringReader;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
import java.util.Set;
import dev.utils.JCLogUtils;
/**
* detail: Gson 工具类
* @author Ttt
*
* Gson 详细使用
*
*/
public final class GsonUtils {
private GsonUtils() {
}
// 日志 TAG
private static final String TAG = GsonUtils.class.getSimpleName();
// Object 转 JSON 字符串
private static final Gson TO_GSON = createGson(true).create();
// JSON 字符串转 T Object
private static final Gson FROM_GSON = createGson(true).create();
// JSON 缩进
private static final Gson INDENT_GSON = createGson(true).setPrettyPrinting().create();
// ============
// = 转换方法 =
// ============
/**
* 将对象转换为 JSON String
* @param object {@link Object}
* @return JSON String
*/
public static String toJson(final Object object) {
return toJson(object, TO_GSON);
}
/**
* 将对象转换为 JSON String
* @param object {@link Object}
* @param gson {@link Gson}
<