io.github.dft.amazon.common.DateDeserializer 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 java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class DateDeserializer extends JsonDeserializer {
@Override
public LocalDateTime deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
String timestamp = jsonParser.getText()
.trim();
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXX");
return LocalDateTime.parse(timestamp, dateTimeFormatter);
}
}