96
//
97
//nolint:revive // allowList is a control flag
98
>
func decodeValueTyped[T any](value *commonpb.Payload, allowList bool) (any, error) {
encode_value.go
99
>
// At first, it tries to decode to pointer of actual type (i.e. `*string` for `string`).
100
>
// This is to ensure that `nil` values are decoded back as `nil` using `NilPayloadConverter`.
101
>
// If value is not `nil` but some value of expected type, the code relies on the fact that
102
>
// search attributes are always encoded with `JsonPayloadConverter`, which uses standard
103
>
// `json.Unmarshal` function, which works fine with pointer types when decoding values.
104
>
// If decoding to pointer type fails, it tries to decode to array of the same type because
105
>
// search attributes support polymorphism: field of specific type may also have an array of that type.
106
>
// If resulting slice has zero length, it gets substitute with `nil` to treat nils and empty slices equally.
107
>
// If allowList is true, it returns the list as it is. If allowList is false and the list has
108
>
// only one element, then return it. Otherwise, return an error.
109
>
// If search attribute value is `nil`, it means that search attribute needs to be removed from the document.
110
>
var val *T
111
>
if err := payload.Decode(value, &val); err == nil {
112
if val == nil {
113
return nil, nil