io.getunleash.util.DateTimeSerializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of unleash-client-java Show documentation
Show all versions of unleash-client-java Show documentation
A client library for Unleash
package io.getunleash.util;
import static java.time.format.DateTimeFormatter.ISO_INSTANT;
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;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
public class DateTimeSerializer implements JsonSerializer {
@Override
public JsonElement serialize(
LocalDateTime localDateTime,
Type type,
JsonSerializationContext jsonSerializationContext) {
return new JsonPrimitive(ISO_INSTANT.format(localDateTime.toInstant(ZoneOffset.UTC)));
}
}