Aws-sdk-go: dynamodbattribute.Marshal([]*string) converts to a List("L"), instead of StringSet("SS")

Created on 9 Nov 2017  路  5Comments  路  Source: aws/aws-sdk-go

Please fill out the sections below to help us address your issue.

Version of AWS SDK for Go?

Version of Go (go version)?

go version go1.9.2

What issue did you see?

I have created a attribute of type String Set in Dynamodb. When I create create the Item and assign an attribute of type SS everything works. But when I try to update this attribute using dynamodbattribute.Marshal(), the data type changes to a list ("L").

Steps to reproduce

If you have have an runnable example, please include it.

documentation guidance

All 5 comments

@Aprimit thanks for reaching out to us. Correct the marshaler assumes a string slice is a list because a string set implies that there are no duplicate values within the list. Since only the application providing the slice to the marshaler knows if the data is actually a set or arbitrary list the application needs to signal the marshaler to process the value as a string set.

It looks like the marshaler doesn't document this condition very well. We should update the documentation to make this more clear.

@jasdel thanks for the quick response. Well, could you please provide an example of how to signal the marshaler to process the slice as stringset ?

Sure the dynamodbav:",stringset" struct tag is the best way to tell the marshaler that the field should be treated as a string set instead of a list.

e.g

type MyType struct {
    // Field will be marshaled as a string set
    Field []string `dynamodbav:",stringset"`
}

@jasdel the suggested solution works for me. Appreciate your help here. Thank you 馃憤

Was this page helpful?
0 / 5 - 0 ratings