Skip to content

[Bug]: Datetime not parsing the timestamp. #333

Closed
@LWhitakerEasypost

Description

@LWhitakerEasypost

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    triageIssue is being researched

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions