com.gitee.easyopen.util.JsonUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of easyopen-mini Show documentation
Show all versions of easyopen-mini Show documentation
easyopen mini版,保留基本签名校验,文档功能。https://gitee.com/durcframework/easyopen
package com.gitee.easyopen.util;
import com.gitee.easyopen.serializer.LocalDateTimeSerializer;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
/**
* json工具类,兼容fastjson用法(非100%兼容,只封装了常用方法)
*/
public class JsonUtil {
private static final String DATETIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
/**
* Gson实例线程安全,声明一个即可。文档中有说明:
* Gson instances are Thread-safe so you can reuse them freely across multiple threads
*/
private static Gson gson = new GsonBuilder()
.registerTypeAdapter(LocalDateTime.class, new LocalDateTimeSerializer(DATETIME_PATTERN))
.setDateFormat(DATETIME_PATTERN)
.create();
private static final Type TYPE_STRING_MAP = new TypeToken