Support alternate date formats in StateMachine.fromJson(). #3095
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue: #2130
Issue Being Resolved
Currently, this code:
fails with the error message
java.lang.IllegalArgumentException: Invalid format: "2016-03-14T01:59:00Z" is malformed at "Z"
.However, this code:
works.
This is because we currently use:
to parse dates found in JSON.
According to the AWS Step Functions documentation for the wait state:
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.