Skip to content

Commit

Permalink
Support alternate date formats in StateMachine.fromJson().
Browse files Browse the repository at this point in the history
  • Loading branch information
mcvayc committed Feb 15, 2024
1 parent 3966385 commit 51f18de
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package com.amazonaws.services.stepfunctions.builder.internal;

import com.amazonaws.util.DateUtils;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
Expand Down Expand Up @@ -59,7 +60,7 @@ public Date deserialize(JsonParser jsonParser,
}

public static Date fromJson(String jsonText) {
return FORMATTER.parseDateTime(jsonText).toDate();
return DateUtils.parseISO8601Date(jsonText);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -667,4 +667,18 @@ public void stateMachineFromJson_MalformedJson_ThrowsException() {
StateMachine.fromJson("{");
}

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

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

}

0 comments on commit 51f18de

Please sign in to comment.