com.github.nagyesta.lowkeyvault.http.management.EpochSecondsDeserializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lowkey-vault-client Show documentation
Show all versions of lowkey-vault-client Show documentation
HTTP Client provider for Lowkey Vault tests.
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);
}
}