EasyPost/easypost-java

[Bug]: Datetime not parsing the timestamp.

Closed this issue · 2 comments

Software Version

v7.4.2

Language Version

java 17.0.9 2023-10-17 LTS

Operating System

Locally macOS 14.6.1, deployed to kube-helm ECR img OS/Arch: Linux, x86-64, ARM 64

What happened?

I wanted to check how we can get the time portion of datetime fields like created_at and updated_at using the Java SDK (I understand that it could be done by calling the API directly).

Right now, I saw that Date parsing comes from the GSON DateDeserializer, however the loop in the function below, always circuit-breaks at the first given DATE_FORMATS which is "yyyy-MM-dd" (and therefore ignoring the time portion when deserializing).

@Override
public Date deserialize(JsonElement json, Type type, JsonDeserializationContext context)
    throws JsonParseException {
    for (String format : DATE_FORMATS) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(format);
            sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
            return sdf.parse(json.getAsString());
        } catch (ParseException e) {
            throw new JsonParseException("Unable to parse this date format");
        }
    }
    throw new JsonParseException("Unparseable date: \"" + json.getAsString() + "\"");
}

When called from https://github.com/EasyPost/easypost-java/blob/master/src/main/java/com/easypost/http/Requestor.java#L618

As classes are final and instantiated, not injected, I didn't not find a straightforward way to override the behavior of this serializer. What do you suggest? For some fields like est_delivered_date, and tracker datetime we do need to capture the time portion.

What was expected?

The timestamp portion of the "datetime" would be captured and parsed correctly.

Sample Code

No response

Relevant logs

No response

Thanks for bringing this to our attention. We are triaging this.

@LWhitakerEasypost Thanks for the Github Issue. DateDeserailizer was added for the Claims API which we launched two months ago, we have fixed the API level to ensure Z always returns at the end of time format. So DateDeserailizer is removed, you can update to v7.4.3 and that should fix the issue