Replies: 3 comments
-
Slices are value types in Go. This article does an excellent job at breaking down how this works internally. You must pass a pointer to a value to be unmarshaled: records := make([]map[string]string, 2)
err := attributevalue.UnmarshalListOfMaps(items, &records)
// ^ You can observe that var v []string
if err := json.Unmarshal([]byte(`["1", "2"]`), v); err != nil {
log.Fatal(err)
} If this is confusing, I think it helps to imagine a case where we tried to do this with a scalar: var v int
if err := json.Unmarshal([]byte(`1`), v); err != nil {
log.Fatal(err)
} v is an integer value. |
Beta Was this translation helpful? Give feedback.
-
Note also that the member type of the slice is irrelevant - be it struct or anything else. |
Beta Was this translation helpful? Give feedback.
-
@lucix-aws |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the bug
I'm sorry if I may misunderstand the usage of UnmarshalListOfMaps, but let me make this report.
I tried to use attributevalue.UnmarshalListOfMaps to convert Items of dynamodb.ExecuteStatementOutput to list of custom struct, but It was failed with the next error.
Actually, I found the following message from api document, so I interpreted that we could utilize the function to convert the multiple items of DynamoDB's query result to []<custon struct> or []map[string]<any type>
Expected Behavior
UnmarshalListOfMaps can be used to convert []map[string]types.AttributeValue to []<custom struct>
Current Behavior
UnmarshalListOfMaps cannot be used to convert []map[string]types.AttributeValue to []<custom struct>.
Reproduction Steps
For example, the next minimum code gets failed.
Output is the following.
And also for next example with []map[string]string, we get failed.
Possible Solution
If my recognition is correct, I think it should use UnmarshalMap to each Items with instead of UnmarshalList here as behavior. But, It may be not simple code.
Additional Information/Context
No response
AWS Go SDK V2 Module Versions Used
Compiler and Version used
go version go1.22.0 linux/amd64
Operating System and version
Ubuntu 20.04.4 LTS
Beta Was this translation helpful? Give feedback.
All reactions