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

io.github.dft.amazon.common.LocalDateTimeDeserializer Maven / Gradle / Ivy

There is a newer version: 2.1.9
Show newest version
package io.github.dft.amazon.common;

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

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class LocalDateTimeDeserializer extends JsonDeserializer {

    private static final DateTimeFormatter ISO_8601_TIMESTAMP_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss[.SSS]'Z'");

    @Override
    @SneakyThrows
    public LocalDateTime deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) {
        String timestamp = jsonParser.getText()
                                     .trim();
        return LocalDateTime.parse(timestamp, ISO_8601_TIMESTAMP_FORMATTER);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy