Can not use interface type as activity input and output?

Hi,
I got this error when doing this

“err”:“payload item 0: value type: interface {}: must be a concrete type, not interface”

func Activity(ctx context.Context, input interface{}) interface{} {return something}

var result interface{}
workflow.ExecuteActivity(ctx, Activity, input).Get(ctx, result)

am i missing something?

Yes, you cannot unmarshal to an empty interface using the default converters because the default converters use the type to know how to unmarshal. There is no “default” type for the data using default converters like there is with json. You can however supply your own data converter which could unmarshal from a raw payload to interface{}.

Thanks for the reply, do you have an example for the customized converter? is it an interface provided by temporal sdk?

Interface: converter package - go.temporal.io/sdk/converter - pkg.go.dev
Sample: samples-go/cryptconverter at master · temporalio/samples-go · GitHub

Yes, see samples-go/cryptconverter at master · temporalio/samples-go · GitHub and samples-go/encrypted-payloads at master · temporalio/samples-go · GitHub.

Yes at converter package - go.temporal.io/sdk/converter - pkg.go.dev. It can be provided via client options or set on the workflow context for some scenarios.

(EDIT: Sorry, missed @tihomir’s update)

func Activity(ctx context.Context, input interface{}) interface{} {return something}

What is something here? I guess it is some proto message. Because with plain string, this works fine (modified helloworld example):

func Activity(ctx context.Context, name string) (interface{}, error) {
	return "Hello " + name + "!", nil
}

func Workflow(ctx workflow.Context, name string) (interface{}, error) {
//...
	var result interface{}
	err := workflow.ExecuteActivity(ctx, Activity, name).Get(ctx, &result)
//...
	return result, nil
}

	we, err := c.ExecuteWorkflow(context.Background(), workflowOptions, helloworld.Workflow, "Temporal")
	var result interface{}
	err = we.Get(context.Background(), &result)

yes, the something is a proto msg

So there is no way to unmarshal proto message to interface{}. You should use plain go struct there or specify exact type when unmarshal.

In case of plain go struct you will get map[string]interface{} in you variable of interface{} type. It is built-in json.Unmarshal underneath.