com.devcycle.sdk.server.local.utils.LongTimestampDeserializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-server-sdk Show documentation
Show all versions of java-server-sdk Show documentation
Server side SDK to interact with DevCycle.
package com.devcycle.sdk.server.local.utils;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.fasterxml.jackson.databind.exc.InvalidFormatException;
import java.io.IOException;
import java.time.Instant;
import java.time.format.DateTimeParseException;
public class LongTimestampDeserializer extends StdDeserializer {
public LongTimestampDeserializer() {
super(Long.class);
}
@Override
public Long deserialize(JsonParser parser, DeserializationContext ctxt)
throws IOException {
String timestamp = parser.getText();
try {
return Instant.parse(timestamp).toEpochMilli();
} catch (DateTimeParseException dtpe) {
throw new InvalidFormatException(
parser, dtpe.getMessage(), timestamp, Long.class);
}
}
}