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

com.devcycle.sdk.server.local.utils.LongTimestampDeserializer Maven / Gradle / Ivy

There is a newer version: 2.3.0
Show newest version
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);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy