dynamodbattribute.UnmarshalMap casts empty Lists to nil #1890
Closed
Description
Please fill out the sections below to help us address your issue.
Version of AWS SDK for Go?
v1.13.16
Version of Go (go version
)?
1.9.3
What issue did you see?
When I have a record with an empty list in dynamodb, and I read it with the go sdk, and call dynamodbattribute.UnmarshalMap
, then empty list values are cast to nil.
Steps to reproduce
Create an record with an empty list on the CLI:
aws dynamodb put-item --table-name resources \
--item '{"id": { "S": "555" }, "foo": { "L": [] }}'
Then fetch the record and unmarshal it:
params := &dynamodb.GetItemInput{
Key: map[string]*dynamodb.AttributeValue{
"id": {
S: aws.String(id),
},
},
TableName: aws.String(myTableName),
ConsistentRead: aws.Bool(true),
}
resp, err := svc.GetItem(params)
...
var json map[string]interface{}
if err := dynamodbattribute.UnmarshalMap(resp.Item, &json); err != nil {
panic(err)
}
log.Printf("JSON: %s", json)
The output is:
Item: map[id:555 foo:<nil>]
But I would expect:
Item: map[id:555 foo:[]]
If you have have an runnable example, please include it.