/
okz
/
itmo-java-lab5
Обзор
Документация
Войти
/
okz
/
itmo-java-lab5
Код
Запросы
0
Задачи
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/client/typeadapters/LocalDateTimeTypeAdapter.java
27 строк
932 B
knyazhe
i change something
21 сен 2024, 03:22
21 сен 2024, 03:22
a769d98
Код
Авторство
О чём код?
package client.typeadapters; import com.google.gson.*; import java.lang.reflect.Type; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.Locale; public class LocalDateTimeTypeAdapter implements JsonSerializer<LocalDateTime>, JsonDeserializer<LocalDateTime> { private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d::MMM::uuuu HH::mm::ss").localizedBy(Locale.UK); @Override public JsonElement serialize(LocalDateTime localDateTime, Type srcType, JsonSerializationContext context) { return new JsonPrimitive(formatter.format(localDateTime)); } @Override public LocalDateTime deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { return LocalDateTime.parse(json.getAsString(), formatter); } }