com.mailchimp.jackson.MailChimpZonedDateTimeDeserializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mailchimp-java Show documentation
Show all versions of mailchimp-java Show documentation
Java client to communicate with MailChimp API 3.0
The newest version!
package com.mailchimp.jackson;
import java.io.IOException;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
/**
* @author stevensnoeijen
*/
public final class MailChimpZonedDateTimeDeserializer extends JsonDeserializer {
private final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
@Override
public ZonedDateTime deserialize(final JsonParser parser, final DeserializationContext context)
throws IOException, JsonProcessingException {
final String stringDate = parser.getText();
if (stringDate == null || stringDate.isEmpty()) {
return null;
}
try {
ZonedDateTime date = ZonedDateTime.parse(stringDate, dateTimeFormatter);
return date;
} catch (DateTimeParseException ex) {
//when format is incorrect set to null
return null;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy