mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-08 22:29:33 +00:00
fix for date
This commit is contained in:
parent
b7ab83efdd
commit
b5b196fd65
@ -14,7 +14,7 @@
|
|||||||
package com.basistech.df.cybertriage.autopsy.ctapi.json;
|
package com.basistech.df.cybertriage.autopsy.ctapi.json;
|
||||||
|
|
||||||
import com.basistech.df.cybertriage.autopsy.ctapi.util.ObjectMapperUtil.InstantEpochMillisDeserializer;
|
import com.basistech.df.cybertriage.autopsy.ctapi.util.ObjectMapperUtil.InstantEpochMillisDeserializer;
|
||||||
import com.basistech.df.cybertriage.autopsy.ctapi.util.ObjectMapperUtil.ZonedDateTimeDeserializer;
|
import com.basistech.df.cybertriage.autopsy.ctapi.util.ObjectMapperUtil.MDYDateDeserializer;
|
||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
@ -41,7 +41,7 @@ public class DecryptedLicenseResponse {
|
|||||||
public DecryptedLicenseResponse(
|
public DecryptedLicenseResponse(
|
||||||
@JsonProperty("boostLicenseId") String boostLicenseId,
|
@JsonProperty("boostLicenseId") String boostLicenseId,
|
||||||
@JsonProperty("licenseHostId") String licenseHostId,
|
@JsonProperty("licenseHostId") String licenseHostId,
|
||||||
@JsonDeserialize(using = ZonedDateTimeDeserializer.class)
|
@JsonDeserialize(using = MDYDateDeserializer.class)
|
||||||
@JsonProperty("expirationDate") ZonedDateTime expirationDate,
|
@JsonProperty("expirationDate") ZonedDateTime expirationDate,
|
||||||
@JsonProperty("hashLookups") Long hashLookups,
|
@JsonProperty("hashLookups") Long hashLookups,
|
||||||
@JsonProperty("fileUploads") Long fileUploads,
|
@JsonProperty("fileUploads") Long fileUploads,
|
||||||
|
@ -25,12 +25,15 @@ import java.text.ParseException;
|
|||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.time.DateTimeException;
|
import java.time.DateTimeException;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.ZoneOffset;
|
import java.time.ZoneOffset;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.time.format.DateTimeFormatterBuilder;
|
||||||
import java.time.format.DateTimeParseException;
|
import java.time.format.DateTimeParseException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -55,14 +58,23 @@ public class ObjectMapperUtil {
|
|||||||
return defaultMapper;
|
return defaultMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class UTCBaseZonedDateTimeDeserializer extends JsonDeserializer<ZonedDateTime> {
|
||||||
public static class ZonedDateTimeDeserializer extends JsonDeserializer<ZonedDateTime> {
|
|
||||||
|
private final DateTimeFormatter formatter;
|
||||||
|
|
||||||
|
public UTCBaseZonedDateTimeDeserializer(DateTimeFormatter formatter) {
|
||||||
|
this.formatter = formatter;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ZonedDateTime deserialize(JsonParser jp, DeserializationContext dc) throws IOException, JacksonException {
|
public ZonedDateTime deserialize(JsonParser jp, DeserializationContext dc) throws IOException, JacksonException {
|
||||||
String date = jp.getText();
|
String date = jp.getText();
|
||||||
|
if (date == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
LocalDateTime ldt = LocalDateTime.parse(date, DateTimeFormatter.ISO_LOCAL_DATE_TIME);
|
LocalDateTime ldt = LocalDateTime.parse(date, formatter);
|
||||||
return ZonedDateTime.of(ldt, ZoneOffset.UTC);
|
return ZonedDateTime.of(ldt, ZoneOffset.UTC);
|
||||||
} catch (DateTimeParseException ex) {
|
} catch (DateTimeParseException ex) {
|
||||||
return null;
|
return null;
|
||||||
@ -70,22 +82,40 @@ public class ObjectMapperUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// public static class MDYDateDeserializer extends JsonDeserializer<Date> {
|
public static class ZonedDateTimeDeserializer extends UTCBaseZonedDateTimeDeserializer {
|
||||||
//
|
|
||||||
// private static final SimpleDateFormat FORMATTER = new SimpleDateFormat("MMM dd, yyyy");
|
public ZonedDateTimeDeserializer() {
|
||||||
//
|
super(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
|
||||||
// @Override
|
}
|
||||||
// public Date deserialize(JsonParser jp, DeserializationContext dc) throws IOException, JacksonException {
|
}
|
||||||
// JsonNode node = jp.getCodec().readTree(jp);
|
|
||||||
// String nodeText = node.asText();
|
public static class MDYDateDeserializer extends JsonDeserializer<ZonedDateTime> {
|
||||||
// try {
|
|
||||||
// return FORMATTER.parse(nodeText);
|
private final DateTimeFormatter formatter;
|
||||||
// } catch (ParseException ex) {
|
|
||||||
// return null;
|
public MDYDateDeserializer() {
|
||||||
// }
|
this.formatter = new DateTimeFormatterBuilder()
|
||||||
// }
|
.parseCaseInsensitive()
|
||||||
//
|
.appendPattern("MMM d, [uuuu][uu]")
|
||||||
// }
|
.toFormatter(Locale.ENGLISH);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ZonedDateTime deserialize(JsonParser jp, DeserializationContext dc) throws IOException, JacksonException {
|
||||||
|
String date = jp.getText();
|
||||||
|
if (date == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
LocalDate ld = LocalDate.parse(date, formatter);
|
||||||
|
LocalDateTime ldt = ld.atStartOfDay();
|
||||||
|
return ZonedDateTime.of(ldt, ZoneOffset.UTC);
|
||||||
|
} catch (DateTimeParseException ex) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class EpochTimeDeserializer<T> extends JsonDeserializer<T> {
|
public static class EpochTimeDeserializer<T> extends JsonDeserializer<T> {
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user