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

Use generic and the serializer interface to return the actual object for workflow activity

Open skyao opened this issue 1 year ago • 1 comments

This issue is to follow the discussion in PR https://github.com/dapr/java-sdk/pull/880

====================

artursouza: Use generic and the serializer interface to return the actual object. See how it is done for DaprClient

skyao: this run() method defined in WorkflowActivity doesn't have a input parameter, we need to call ctx.getInput() to get the input, like this:

public Object run(WorkflowActivityContext ctx) {
    OrderPayload order = ctx.getInput(OrderPayload.class);
    logger.info("Requesting approval for order: {}", order);

    return ApprovalResult.Approved;
}

I suggest to move this input parameter from ctx to run() method:

public interface WorkflowActivity<Input, Output>{ Output run(WorkflowActivityContext ctx, Input input); }

artursouza: Exactly. Also, use TypeRef from the main SDK. See how we do it for Actors and state store.

skyao avatar Sep 13 '23 08:09 skyao