io.github.dft.amazon.common.LocalDateTimeDeserializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of amazon-sp-api Show documentation
Show all versions of amazon-sp-api Show documentation
Amazon SP API using JDK 11
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);
}
}