@@ -1268,3 +1268,79 @@ func TestUnmarshalBinary(t *testing.T) {
1268
1268
t .Errorf ("expected %v, got %v" , expected , actual )
1269
1269
}
1270
1270
}
1271
+
1272
+ type testStringItem string
1273
+
1274
+ func (t * testStringItem ) UnmarshalDynamoDBStreasmAttributeValue (av types.AttributeValue ) error {
1275
+ v , ok := av .(* types.AttributeValueMemberS )
1276
+ if ! ok {
1277
+ return fmt .Errorf ("expecting string value" )
1278
+ }
1279
+ * t = testStringItem (v .Value )
1280
+ return nil
1281
+ }
1282
+
1283
+ type testNumberItem float64
1284
+
1285
+ func (t * testNumberItem ) UnmarshalDynamoDBStreamsAttributeValue (av types.AttributeValue ) error {
1286
+ v , ok := av .(* types.AttributeValueMemberN )
1287
+ if ! ok {
1288
+ return fmt .Errorf ("expecting number value" )
1289
+ }
1290
+ n , err := strconv .ParseFloat (v .Value , 64 )
1291
+ if err != nil {
1292
+ return err
1293
+ }
1294
+ * t = testNumberItem (n )
1295
+ return nil
1296
+ }
1297
+
1298
+ type testBinaryItem []byte
1299
+
1300
+ func (t * testBinaryItem ) UnmarshalDynamoDBStreamsAttributeValue (av types.AttributeValue ) error {
1301
+ v , ok := av .(* types.AttributeValueMemberB )
1302
+ if ! ok {
1303
+ return fmt .Errorf ("expecting binary value" )
1304
+ }
1305
+ * t = make ([]byte , len (v .Value ))
1306
+ copy (* t , v .Value )
1307
+ return nil
1308
+ }
1309
+
1310
+ type testStringSetWithUnmarshaler struct {
1311
+ Strings []testStringItem `dynamodbav:",stringset"`
1312
+ Numbers []testNumberItem `dynamodbav:",numberset"`
1313
+ Binaries []testBinaryItem `dynamodbav:",binaryset"`
1314
+ }
1315
+
1316
+ func TestUnmarshalIndividualSetValues (t * testing.T ) {
1317
+ in := & types.AttributeValueMemberM {
1318
+ Value : map [string ]types.AttributeValue {
1319
+ "Strings" : & types.AttributeValueMemberSS {
1320
+ Value : []string {"a" , "b" },
1321
+ },
1322
+ "Numbers" : & types.AttributeValueMemberNS {
1323
+ Value : []string {"1" , "2" },
1324
+ },
1325
+ "Binaries" : & types.AttributeValueMemberBS {
1326
+ Value : [][]byte {{1 , 2 }, {3 , 4 }},
1327
+ },
1328
+ },
1329
+ }
1330
+ var actual testStringSetWithUnmarshaler
1331
+ err := UnmarshalWithOptions (in , & actual , func (o * DecoderOptions ) {
1332
+ o .FixUnmarshalIndividualSetValues = true
1333
+ })
1334
+ if err != nil {
1335
+ t .Fatalf ("expect no error, got %v" , err )
1336
+ }
1337
+
1338
+ expected := testStringSetWithUnmarshaler {
1339
+ Strings : []testStringItem {"a" , "b" },
1340
+ Numbers : []testNumberItem {1 , 2 },
1341
+ Binaries : []testBinaryItem {{1 , 2 }, {3 , 4 }},
1342
+ }
1343
+ if diff := cmpDiff (expected , actual ); diff != "" {
1344
+ t .Errorf ("expect value match\n %s" , diff )
1345
+ }
1346
+ }
0 commit comments