19 package com.basistech.df.cybertriage.autopsy.ctapi.util;
21 import com.fasterxml.jackson.core.JsonParser;
22 import com.fasterxml.jackson.core.JacksonException;
23 import com.fasterxml.jackson.databind.DeserializationContext;
24 import com.fasterxml.jackson.databind.JsonDeserializer;
25 import com.fasterxml.jackson.databind.JsonNode;
26 import com.fasterxml.jackson.databind.ObjectMapper;
27 import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
28 import java.io.IOException;
29 import java.time.DateTimeException;
30 import java.time.Instant;
31 import java.time.LocalDate;
32 import java.time.LocalDateTime;
33 import java.time.ZoneOffset;
34 import java.time.ZonedDateTime;
35 import java.time.format.DateTimeFormatter;
36 import java.time.format.DateTimeFormatterBuilder;
37 import java.time.format.DateTimeParseException;
38 import java.util.Locale;
39 import java.util.function.Function;
57 ObjectMapper defaultMapper =
new ObjectMapper();
58 defaultMapper.registerModule(
new JavaTimeModule());
71 public ZonedDateTime
deserialize(JsonParser jp, DeserializationContext dc)
throws IOException, JacksonException {
72 String date = jp.getText();
78 LocalDateTime ldt = LocalDateTime.parse(date, formatter);
79 return ZonedDateTime.of(ldt, ZoneOffset.UTC);
80 }
catch (DateTimeParseException ex) {
89 super(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
98 this.formatter =
new DateTimeFormatterBuilder()
99 .parseCaseInsensitive()
100 .appendPattern(
"MMM d, [uuuu][uu]")
101 .toFormatter(Locale.ENGLISH);
105 public ZonedDateTime
deserialize(JsonParser jp, DeserializationContext dc)
throws IOException, JacksonException {
106 String date = jp.getText();
112 LocalDate ld = LocalDate.parse(date, formatter);
113 LocalDateTime ldt = ld.atStartOfDay();
114 return ZonedDateTime.of(ldt, ZoneOffset.UTC);
115 }
catch (DateTimeParseException ex) {
130 public T
deserialize(JsonParser jp, DeserializationContext dc)
throws IOException, JacksonException {
131 JsonNode node = jp.getCodec().readTree(jp);
134 if (node.isNumber()) {
135 timeVal = node.asLong();
137 String nodeText = node.asText();
139 timeVal = Long.parseLong(nodeText);
140 }
catch (NumberFormatException ex) {
145 if (timeVal != null) {
147 return timeDeserializer.apply(timeVal);
148 }
catch (DateTimeException ex) {
163 private static Instant
convert(Long longVal) {
165 return Instant.ofEpochMilli(longVal);
166 }
catch (DateTimeException ex) {
180 private static Instant
convert(Long longVal) {
182 return Instant.ofEpochSecond(longVal);
183 }
catch (DateTimeException ex) {
InstantEpochMillisDeserializer()
UTCBaseZonedDateTimeDeserializer(DateTimeFormatter formatter)
static Instant convert(Long longVal)
EpochTimeDeserializer(Function< Long, T > timeDeserializer)
static ObjectMapperUtil getInstance()
final Function< Long, T > timeDeserializer
static Instant convert(Long longVal)
ZonedDateTimeDeserializer()
ZonedDateTime deserialize(JsonParser jp, DeserializationContext dc)
T deserialize(JsonParser jp, DeserializationContext dc)
ObjectMapper getDefaultObjectMapper()
static final ObjectMapperUtil instance
ZonedDateTime deserialize(JsonParser jp, DeserializationContext dc)
InstantEpochSecsDeserializer()
final DateTimeFormatter formatter
final DateTimeFormatter formatter