All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.getunleash.util.DateTimeSerializer Maven / Gradle / Ivy

The newest version!
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)));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy