package nju.seec.helper.util; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import lombok.experimental.UtilityClass; import nju.seec.helper.util.serializer.LocalDateTimeSerializer; import java.time.LocalDateTime; /** * @author cst */ @UtilityClass public class JsonUtils { private static final Gson GSON = new GsonBuilder().setPrettyPrinting().registerTypeAdapter(LocalDateTime.class, new LocalDateTimeSerializer()).create(); public String toJson(Object o) { return GSON.toJson(o); } public T fromJson(String json, Class classOfT) { return GSON.fromJson(json, classOfT); } }