-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
service/dynamodb/dynamodbattribute: Add marshaling nil map as empty map #2419
Conversation
…s empty map Adds support for marshaling nil maps and slices as empty maps and lists instead of NULL DynamoDB AttributeValue. Fix aws#682 Related: aws/aws-sdk-go-v2#195 Original PR: aws#2105
While adding documentation for this feature, I came across a few areas that I think might be confusing for this feature. Specifically the difference between nil vs empty of a slice/map, along with the marshaler's behavior on when elements are set or not set on the user's side during marshal. To help clarify this I think renaming NilAsEmpty to |
@jasdel do you use this code yourself ? we also have a need to save empty maps and slices correctly (not as nil) in dynamodb. |
Thanks for asking @gobadiah. Could you share more information on your use case. In making this change, it became evident that (un)marshaler's default behavior for handling of maps and slices insufficient. In building out this PR, I think the (un)marshaler's behavior should be that nil maps/slices are sent to DynamoDB as nil, and non-nil empty maps/slices should be stored as empty maps and lists in DynamoDB. With the same behavior for unmarshaling DynamoDB items to Go types. With the exception of members decorated as I think the PR should be updated to include this behavior. |
Our use case is pretty much exactly the same. Right now if we save empty map / slice we get back a nil value, which forces us to put all kind of custom logic to handle these cases. I've read past issues but I don't really understand the reasoning behind the current behaviour, and why this change is not getting more support. Do you have a workaround or are you using your own fork to get around this limitation ? |
Fixes #2746 |
Replaced by #2834 |
Adds support for optionally marshaling nil maps and slices as empty maps and lists instead of NULL DynamoDB AttributeValue.
Adds
keepempty
struct tag for marshaling and unmarshaling structs. Maps and Slices decorated with this struct tag if nil or empty will be marshaled as empty lists, maps, sets, etc instead of default NULL value.Adds
MarshalOptions
KeepEmpty
encoder and decoder marshaling options. Has same effect as thekeepempty
struct tag, but applying to all members marshaled.Fix #682 #1890
Related: aws/aws-sdk-go-v2#195
Related PRs: #2105, #2032
TODO:
keepempty
tag,KeepEmpty
option, andomitempty
tag.