Override DataConverter for specific activity

I have created my custom data converter, and now I hope to override DataConverter for only a few specific activities.

I saw comments on the temporal code:
To override DataConverter for specific activity or child workflow use workflow.WithDataConverter to create new Context, and pass that context to ExecuteActivity/ExecuteChildWorkflow calls.

When I try to use workflow.WithDataConverter and pass the context to ExecuteActivity, I faced error:
"unable to decode the activity function input payload with error: payload item 0: unable to decode: invalid character 'P' looking for beginning of value for function name

FYI If I avoid using withDataConverter and use just ToPayloads and FromPayloads, it works good. Am I missing any thing? Thanks for your help, really appreciated it

Yes, that is for overriding the data converter for calling the activity but that does not affect what happens when the activity is received by the worker for execution. For overriding it at the worker for handling the call of the activity there are a few ways. The most obvious would be to use a different worker/client with the data converter you’d like if the activity is on a different task queue from your other workers/activities.

Overriding a data converter per activity is probably a poor practice. Rather, having custom data conversion per type and having a common data converter be smart enough to determine what to do based on type (or metadata) is much more reasonable. Of course, using default data conversion is the best unless you really need custom.

Thanks for the quick response! Reason of using a custom data converter is because I want to encrypt payloads and send them over to the Temporal server which I think the default data conversion doesn’t provide the encryption

You should apply this at a higher level instead of per activity. See how samples-go/encryption at main · temporalio/samples-go · GitHub does this.