com.github.nagyesta.lowkeyvault.http.management.EpochSecondsSerializer 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.
package com.github.nagyesta.lowkeyvault.http.management;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
import java.time.OffsetDateTime;
import java.util.Optional;
public class EpochSecondsSerializer extends JsonSerializer {
@Override
public void serialize(final OffsetDateTime value, final JsonGenerator generator, final SerializerProvider provider) throws IOException {
final Optional optional = Optional.ofNullable(value);
if (optional.isPresent()) {
final long epochSeconds = optional
.map(OffsetDateTime::toEpochSecond)
.get();
generator.writeNumber(epochSeconds);
} else {
generator.writeNull();
}
}
}