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

com.github.nagyesta.lowkeyvault.http.management.EpochSecondsDeserializer Maven / Gradle / Ivy

The newest version!
package com.github.nagyesta.lowkeyvault.http.management;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

import java.io.IOException;
import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.util.Optional;

public class EpochSecondsDeserializer extends JsonDeserializer {

    @Override
    public OffsetDateTime deserialize(final JsonParser parser, final DeserializationContext context) throws IOException {
        return Optional.ofNullable(parser.readValueAs(Long.class))
                .map(Instant::ofEpochSecond)
                .map((Instant instant) -> OffsetDateTime.ofInstant(instant, ZoneOffset.UTC))
                .orElse(null);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy