| 123456789101112131415161718192021222324 |
- 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> T fromJson(String json, Class<T> classOfT) {
- return GSON.fromJson(json, classOfT);
- }
- }
|