aws-sdk-java icon indicating copy to clipboard operation
aws-sdk-java copied to clipboard

Support alternate date formats in StateMachine.fromJson().

Open mcvayc opened this issue 1 year ago • 2 comments

Issue: #2130

Issue Being Resolved

Currently, this code:

StateMachine.fromJson("""
  {
    "StartAt": "TestTime",
    "States": {
      "TestTime": {
        "Type": "Wait",
        "Timestamp": "2016-03-14T01:59:00Z",
        "End": true
      }
    }
  }
  """);

fails with the error message java.lang.IllegalArgumentException: Invalid format: "2016-03-14T01:59:00Z" is malformed at "Z".

However, this code:

StateMachine.fromJson("""
  {
    "StartAt": "TestTime",
    "States": {
      "TestTime": {
        "Type": "Wait",
        "Timestamp": "2016-03-14T01:59:00.000Z",
        "End": true
      }
    }
  }
  """);

works.

This is because we currently use:

org.joda.time.format.ISODateTimeFormat.dateTime().parseDateTime()

to parse dates found in JSON.

According to the AWS Step Functions documentation for the wait state:

Timestamps must conform to the RFC3339 profile of ISO 8601, 
with the further restrictions that an uppercase T must separate the date and time portions, 
and an uppercase Z must denote that a numeric time zone offset is not present, 
for example, 2024-08-18T17:33:00Z.

The RFC3339 profile of ISO 8601 allows fractional seconds to be optional and the example given in the AWS documentation does not include any partial seconds. Therefore, we should support dates without fractional seconds.

Proposed Solution This PR changes the date parsing logic to use com.amazonaws.util.DateUtils.parseISO8601Date(...) to parse dates during JSON deserialization. This method supports both the date format with fractional seconds and without fractional seconds.

This PR does not change the JSON serialization format of dates.

Test Cases I have added test cases to demonstrate that the solution works with both date formats, however, these test cases may have limited value since I have not changed any date parsing logic used during JSON deserialization. I am happy to remove them upon request.

Confirmation By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

mcvayc avatar Feb 15 '24 22:02 mcvayc

Hi team,

This is my first open-source PR so I apologize in advance if it's missing something.

I tried running mvn clean install but I was unable to get all of the unit tests to pass even on the master branch. It looks like this is a known issue (#1981) so I verified that in IntelliJ all of the unit tests for the child module I touched passed and that mvn clean install -Dgpg.skip=true -DskipTests succeeds.

mcvayc avatar Feb 16 '24 00:02 mcvayc

Hi team, just want to check in and see if there is anything else I can do to help get this merged. Thanks.

mcvayc avatar Apr 23 '24 16:04 mcvayc

@mcvayc I apologize for the lack of updates here, but we won't merge this in v1. We appreciate your reach out.

debora-ito avatar Jul 10 '24 19:07 debora-ito