Skip to content

Conversation

@nklijia2011
Copy link
Contributor

These two adapters help supports having Thrift and TEnum data types in Java classes.

For class like the following.

class TestData {
    String val1;
    // TBase value;
    HistoryEvent val2;
    // TEnum value;
    EventType val3;
}

With the adapter:

{
  "val1": "test-thrift",
  "val2": "{\"10\":{\"i64\":321},\"20\":{\"i64\":1234567},\"40\":{\"rec\":{\"10\":{\"rec\":{\"10\":{\"str\":\"workflowType1\"}}},\"20\":{\"rec\":{\"10\":{\"str\":\"taskList1\"}}},\"30\":{\"str\":\"aW5wdXQ\"},\"40\":{\"i32\":11},\"60\":{\"str\":\"testIdentity\"}}}}",
  "val3": 11
}

Without the adapter:

{
  "val1": "test-thrift",
  "val2": {
    "eventId": 321,
    "timestamp": 1234567,
    "eventType": null,
    "version": 0,
    "workflowExecutionStartedEventAttributes": {
      "workflowType": {
        "name": "workflowType1"
      },
      "parentWorkflowDomain": null,
      "parentWorkflowExecution": null,
      "parentInitiatedEventId": 0,
      "taskList": {
        "name": "taskList1",
        "kind": null
      },
      "input": {
        "hb": [
          105,
          110,
          112,
          117,
          116
        ],
        "offset": 0,
        "isReadOnly": false,
        "bigEndian": true,
        "nativeByteOrder": false,
        "mark": -1,
        "position": 0,
        "limit": 5,
        "capacity": 5,
        "address": 0
      },
      "executionStartToCloseTimeoutSeconds": 11,
      "taskStartToCloseTimeoutSeconds": 0,
      "childPolicy": null,
      "continuedExecutionRunId": null,
      "initiator": null,
      "continuedFailureReason": null,
      "continuedFailureDetails": null,
      "lastCompletionResult": null,
      "identity": "testIdentity",
      "retryPolicy": null,
      "attempt": 0,
      "expirationTimestamp": 0,
      "cronSchedule": null,
      "firstDecisionTaskBackoffSeconds": 0,
      "__isset_bitfield": 2
    },
    "workflowExecutionCompletedEventAttributes": null,
    "workflowExecutionFailedEventAttributes": null,
    "workflowExecutionTimedOutEventAttributes": null,
    "decisionTaskScheduledEventAttributes": null,
    "decisionTaskStartedEventAttributes": null,
    "decisionTaskCompletedEventAttributes": null,
    "decisionTaskTimedOutEventAttributes": null,
    "decisionTaskFailedEventAttributes": null,
    "activityTaskScheduledEventAttributes": null,
    "activityTaskStartedEventAttributes": null,
    "activityTaskCompletedEventAttributes": null,
    "activityTaskFailedEventAttributes": null,
    "activityTaskTimedOutEventAttributes": null,
    "timerStartedEventAttributes": null,
    "timerFiredEventAttributes": null,
    "activityTaskCancelRequestedEventAttributes": null,
    "requestCancelActivityTaskFailedEventAttributes": null,
    "activityTaskCanceledEventAttributes": null,
    "timerCanceledEventAttributes": null,
    "cancelTimerFailedEventAttributes": null,
    "markerRecordedEventAttributes": null,
    "workflowExecutionSignaledEventAttributes": null,
    "workflowExecutionTerminatedEventAttributes": null,
    "workflowExecutionCancelRequestedEventAttributes": null,
    "workflowExecutionCanceledEventAttributes": null,
    "requestCancelExternalWorkflowExecutionInitiatedEventAttributes": null,
    "requestCancelExternalWorkflowExecutionFailedEventAttributes": null,
    "externalWorkflowExecutionCancelRequestedEventAttributes": null,
    "workflowExecutionContinuedAsNewEventAttributes": null,
    "startChildWorkflowExecutionInitiatedEventAttributes": null,
    "startChildWorkflowExecutionFailedEventAttributes": null,
    "childWorkflowExecutionStartedEventAttributes": null,
    "childWorkflowExecutionCompletedEventAttributes": null,
    "childWorkflowExecutionFailedEventAttributes": null,
    "childWorkflowExecutionCanceledEventAttributes": null,
    "childWorkflowExecutionTimedOutEventAttributes": null,
    "childWorkflowExecutionTerminatedEventAttributes": null,
    "signalExternalWorkflowExecutionInitiatedEventAttributes": null,
    "signalExternalWorkflowExecutionFailedEventAttributes": null,
    "externalWorkflowExecutionSignaledEventAttributes": null,
    "__isset_bitfield": 3
  },
  "val3": "ActivityTaskCompleted"
}

@CLAassistant
Copy link

CLAassistant commented Apr 2, 2019

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@meiliang86
Copy link
Contributor

Add unit test?

@meiliang86
Copy link
Contributor

This looks good to me btw.

@nklijia2011
Copy link
Contributor Author

Feel free to merge it into the master branch, as I don't have the permission to do that.

@nklijia2011
Copy link
Contributor Author

Made some additional change in JsonDataConverter.java

Now I removed the special handling in toData() and fromData() for the Thrift data type. As they can already be supported by the new TypeAdapter of TBase and TEnum.

Another reason I am doing that is: I want to pass thrift parameter for my activity function, and the current special handling for Thrift will cause issue for it.

For a single Thrift parameter
In serialization, it will call toData(), which is going to serialize the Thrift correctly.
In deserialization, it will call fromDataArray() instead of fromData(), which cannot deserialize Thrift correctly. And always return an empty Thrift message.

After this change, I can pass in any number of thrift message as activity parameters

@nklijia2011 nklijia2011 closed this Apr 3, 2019
@nklijia2011 nklijia2011 reopened this Apr 3, 2019
@nklijia2011 nklijia2011 closed this Apr 3, 2019
@nklijia2011 nklijia2011 reopened this Apr 3, 2019
@meiliang86 meiliang86 merged commit b06190d into cadence-workflow:master Apr 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants