Skip to content

Commit 8dd08c4

Browse files
committed
Use correct JsonPath config on history serialization
1 parent c0a8ecc commit 8dd08c4

File tree

4 files changed

+74
-48
lines changed

4 files changed

+74
-48
lines changed

temporal-sdk/src/main/java/io/temporal/internal/common/HistoryJsonUtils.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class HistoryJsonUtils {
4444
Configuration.builder().options(Option.SUPPRESS_EXCEPTIONS).build();
4545

4646
public static String protoJsonToHistoryFormatJson(String protoJson) {
47-
DocumentContext parsed = JsonPath.parse(protoJson);
47+
DocumentContext parsed = JsonPath.parse(protoJson, JSON_PATH_CONFIGURATION);
4848
parsed.map(
4949
EVENT_TYPE_PATH,
5050
(currentValue, configuration) ->

temporal-sdk/src/test/java/io/temporal/internal/common/WorkflowExecutionHistoryTest.java

+26
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,16 @@
1919

2020
package io.temporal.internal.common;
2121

22+
import static java.nio.charset.StandardCharsets.UTF_8;
2223
import static org.junit.Assert.assertEquals;
2324

25+
import com.google.common.io.CharStreams;
2426
import io.temporal.testing.WorkflowHistoryLoader;
27+
import java.io.File;
2528
import java.io.IOException;
29+
import java.io.Reader;
30+
import java.net.URL;
31+
import java.nio.file.Files;
2632
import org.junit.Test;
2733

2834
public class WorkflowExecutionHistoryTest {
@@ -44,4 +50,24 @@ public void addingANewFieldToHistoryJsonShouldProduceTheSameResult() throws IOEx
4450

4551
assertEquals(originalHistory.getLastEvent(), historyWithAnAddedNewField.getLastEvent());
4652
}
53+
54+
@Test
55+
public void deserializeAndSerializeBack() throws IOException {
56+
final String HISTORY_RESOURCE_NAME = "simpleHistory1.json";
57+
58+
ClassLoader classLoader = WorkflowExecutionUtils.class.getClassLoader();
59+
URL resource = classLoader.getResource(HISTORY_RESOURCE_NAME);
60+
String historyUrl = resource.getFile();
61+
File historyFile = new File(historyUrl);
62+
String originalSerializedJsonHistory;
63+
try (Reader reader = Files.newBufferedReader(historyFile.toPath(), UTF_8)) {
64+
originalSerializedJsonHistory = CharStreams.toString(reader);
65+
}
66+
67+
WorkflowExecutionHistory history =
68+
WorkflowHistoryLoader.readHistoryFromResource(HISTORY_RESOURCE_NAME);
69+
70+
String serializedHistory = history.toJson(true);
71+
assertEquals(originalSerializedJsonHistory, serializedHistory);
72+
}
4773
}
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
{
2-
"events": [{
3-
"eventId": "1",
4-
"eventTime": "2020-07-30T00:30:03.082421843Z",
5-
"eventType": "WorkflowExecutionStarted",
6-
"version": "-24",
7-
"taskId": "5242897",
8-
"workflowExecutionStartedEventAttributes": {
9-
"workflowType": {
10-
"name": "SomeName"
11-
},
12-
"taskQueue": {
13-
"name": "SomeQueueName",
14-
"kind": "Normal"
15-
},
16-
"input": null,
17-
"workflowExecutionTimeout": "300s",
18-
"workflowTaskTimeout": "60s",
19-
"originalExecutionRunId": "1fd5d4c8-1590-4a0a-8027-535e8729de8e",
20-
"identity":"",
21-
"firstExecutionRunId": "1fd5d4c8-1590-4a0a-8027-535e8729de8e",
22-
"attempt": 1,
23-
"firstWorkflowTaskBackoff": "0s"
2+
"events": [
3+
{
4+
"eventId": "1",
5+
"eventTime": "2020-07-30T00:30:03.082421843Z",
6+
"eventType": "WorkflowExecutionStarted",
7+
"version": "-24",
8+
"taskId": "5242897",
9+
"workflowExecutionStartedEventAttributes": {
10+
"workflowType": {
11+
"name": "SomeName"
12+
},
13+
"taskQueue": {
14+
"name": "SomeQueueName",
15+
"kind": "Normal"
16+
},
17+
"workflowExecutionTimeout": "300s",
18+
"workflowTaskTimeout": "60s",
19+
"originalExecutionRunId": "1fd5d4c8-1590-4a0a-8027-535e8729de8e",
20+
"firstExecutionRunId": "1fd5d4c8-1590-4a0a-8027-535e8729de8e",
21+
"attempt": 1,
22+
"firstWorkflowTaskBackoff": "0s"
23+
}
2424
}
25-
}]
25+
]
2626
}
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
{
2-
"events": [{
3-
"eventId": "1",
4-
"eventTime": "2020-07-30T00:30:03.082421843Z",
5-
"eventType": "WorkflowExecutionStarted",
6-
"version": "-24",
7-
"taskId": "5242897",
8-
"someNewFieldThatIsAbsentFromTheCurrentProtoSchema": "100500",
9-
"workflowExecutionStartedEventAttributes": {
2+
"events": [
3+
{
4+
"eventId": "1",
5+
"eventTime": "2020-07-30T00:30:03.082421843Z",
6+
"eventType": "WorkflowExecutionStarted",
7+
"version": "-24",
8+
"taskId": "5242897",
109
"someNewFieldThatIsAbsentFromTheCurrentProtoSchema": "100500",
11-
"workflowType": {
12-
"name": "SomeName"
13-
},
14-
"taskQueue": {
15-
"name": "SomeQueueName",
16-
"kind": "Normal"
17-
},
18-
"input": null,
19-
"workflowExecutionTimeout": "300s",
20-
"workflowTaskTimeout": "60s",
21-
"originalExecutionRunId": "1fd5d4c8-1590-4a0a-8027-535e8729de8e",
22-
"identity":"",
23-
"firstExecutionRunId": "1fd5d4c8-1590-4a0a-8027-535e8729de8e",
24-
"attempt": 1,
25-
"firstWorkflowTaskBackoff": "0s"
10+
"workflowExecutionStartedEventAttributes": {
11+
"someNewFieldThatIsAbsentFromTheCurrentProtoSchema": "100500",
12+
"workflowType": {
13+
"name": "SomeName"
14+
},
15+
"taskQueue": {
16+
"name": "SomeQueueName",
17+
"kind": "Normal"
18+
},
19+
"workflowExecutionTimeout": "300s",
20+
"workflowTaskTimeout": "60s",
21+
"originalExecutionRunId": "1fd5d4c8-1590-4a0a-8027-535e8729de8e",
22+
"firstExecutionRunId": "1fd5d4c8-1590-4a0a-8027-535e8729de8e",
23+
"attempt": 1,
24+
"firstWorkflowTaskBackoff": "0s"
25+
}
2626
}
27-
}]
27+
]
2828
}

0 commit comments

Comments
 (0)