|
|
@@ -1,18 +1,24 @@
|
|
|
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 new Gson().toJson(o);
|
|
|
+ return GSON.toJson(o);
|
|
|
}
|
|
|
|
|
|
public <T> T fromJson(String json, Class<T> classOfT) {
|
|
|
- return new Gson().fromJson(json, classOfT);
|
|
|
+ return GSON.fromJson(json, classOfT);
|
|
|
}
|
|
|
}
|