2022-02-07 03:43:37 +00:00
|
|
|
package dev.plex.util.adapter;
|
|
|
|
|
|
|
|
import com.google.gson.JsonElement;
|
|
|
|
import com.google.gson.JsonPrimitive;
|
|
|
|
import com.google.gson.JsonSerializationContext;
|
|
|
|
import com.google.gson.JsonSerializer;
|
|
|
|
|
|
|
|
import java.lang.reflect.Type;
|
2022-02-07 05:06:55 +00:00
|
|
|
import java.time.Instant;
|
2022-02-07 03:43:37 +00:00
|
|
|
import java.time.LocalDateTime;
|
2022-02-07 05:06:55 +00:00
|
|
|
import java.time.ZoneId;
|
|
|
|
import java.time.ZoneOffset;
|
2022-02-07 03:43:37 +00:00
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
|
2022-02-07 05:06:55 +00:00
|
|
|
public class LocalDateTimeSerializer implements JsonSerializer<LocalDateTime>
|
2022-02-07 03:43:37 +00:00
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public JsonElement serialize(LocalDateTime src, Type typeOfSrc, JsonSerializationContext context)
|
|
|
|
{
|
2022-02-07 05:06:55 +00:00
|
|
|
return new JsonPrimitive(src.toInstant(ZoneId.systemDefault().getRules().getOffset(Instant.now())).toEpochMilli());
|
2022-02-07 03:43:37 +00:00
|
|
|
}
|
|
|
|
}
|