gocadence-workflowtemporal-workflowuber-cadence

Why private members are not passed from Cadence activities?


I noticed that when I use a struct consisting of both public and private members, then the private ones are not copied(?) by Cadence activities.

For example I have a struct:

package foo

type Foo struct {
    Name        string
    PublicList  []string
    privateList []string
}

func NewFoo() *Foo {
    return &Foo{
        Name:        "Test",
        PublicList:  []string{"A", "B", "C"},
        privateList: []string{"one", "two"},
    }
}

func (f *Foo) ShowLists() {
    fmt.Println("PublicList: ", f.PublicList, ", privateList: ", f.privateList)
}

I also use other struct, registered as activities struct:

package activities 

type FooActivities struct{}

func (a *FooActivities) NewFoo(ctx context.Context) (*foo.Foo, error) {
    return foo.NewFoo(), nil
}

func (a *FooActivities) ShowLists(ctx context.Context, f *foo.Foo) error {
    f.ShowLists()
    return nil
}

My workflow calls these two activities in a following way:

var f *foo.Foo
workflow.ExecuteActivity(ctx, fooActivities.NewFoo).Get(ctx, &f)
workflow.ExecuteActivity(ctx, fooActivities.ShowLists, f).Get(ctx, nil)

The result, printed by ShowLists function:

PublicList: [A B C] , privateList: []

Why is the private list not initialized as expected? Is this a bug or feature? I couldn't find answer for this question in the Cadence documentation.


Solution

  • Cadence (and Temporal) by default use json.Marshal to serialize and json.Unmarshall to deserialize activity arguments. It doesn't serialize private fields.

    Here is a possible workaround.