Skip to content
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

dynamodb/attributevalue: Consider changing default behavior for empty maps and slices #115

Closed
jasdel opened this issue Jan 31, 2018 · 4 comments · Fixed by #948
Closed
Labels
automation-exempt feature-request A feature should be added or improved.

Comments

@jasdel
Copy link
Contributor

jasdel commented Jan 31, 2018

aws/aws-sdk-go#682 raised an issue that the SDK's dynamodbattribute.Marshal methods will marshal empty slices and maps as NULL. This makes is cumbersome to intentionally have the values marshaled as empty list or map.

Consider if it makes sense to change the logic, so that a non-nil slice/map will marshal to a empty list av.L = []dynamodb.AttributeValue{} or map. av.M = map[string]dynamodb.AttributeValue{}. nil maps or slices would still be marshaled as av.NULL = true.

Issue identified in gitter where using an empty list with the expressions Update caused unexpected errors.

@jasdel
Copy link
Contributor Author

jasdel commented Jan 31, 2018

Example of current workaround, https://play.golang.org/p/RQtGrPP8ee6

@diehlaws diehlaws added investigating This issue is being investigated and/or work is in progress to resolve the issue. and removed investigate labels Jan 3, 2019
@MatejBalantic
Copy link

+1 for this request. I would like to store empty arrays as such

1 similar comment
@famartinez80
Copy link

+1 for this request. I would like to store empty arrays as such

@KaibaLopez KaibaLopez added feature-request A feature should be added or improved. and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Sep 22, 2020
@jasdel jasdel changed the title service/dynamodb/dynamodbattribute: Consider changing default behavior for empty maps and lsices dynamodb/attributevalue: Consider changing default behavior for empty maps and lsices Nov 11, 2020
@jasdel jasdel changed the title dynamodb/attributevalue: Consider changing default behavior for empty maps and lsices dynamodb/attributevalue: Consider changing default behavior for empty maps and slices Nov 11, 2020
jasdel added a commit to jasdel/aws-sdk-go-v2 that referenced this issue Dec 5, 2020
* Fixes aws#895
* Fixes aws#929
* Fixes aws#115 to encode `null` for nil map/slice unless `omitempty` is
  set. Simplifies the rules of `null` vs skipped vs zero value for all
  types.
jasdel added a commit to jasdel/aws-sdk-go-v2 that referenced this issue Dec 8, 2020
* Fixes aws#895
* Fixes aws#929
* Fixes aws#115 to encode `null` for nil map/slice unless `omitempty` is
  set. Simplifies the rules of `null` vs skipped vs zero value for all
  types.
jasdel added a commit to jasdel/aws-sdk-go-v2 that referenced this issue Dec 9, 2020
Adds support for

* Fixes aws#895 - Add support for attribute value marshaling
* Fixes aws#929 - Support Number type aliases of string for support for
  json.Number like types.
* Fixes aws#115 - Simplifies the rules of `null` vs skipped vs zero value
  for all types.
  * All nil pointers, map, slice members are serialized as NULL.
  * omitempty struct tag skips zero value of members with the struct
    tag.
  * Empty and Nil Sets (NS, BS, SS) are serialized to null
    by default unless `NullEmptySets` EncoderOptions is set to false. True
    by default. Nil sets are always serialized as NULL, unless the
    `omitempty` struct tag is used.
  * Adds `nullempty` and `nullemptyelem` struct tags to direct if the
    encoder should marshal the member as a AttributeValue NULL if the
    member's value is the type's zero value, (e.g. "" for string, 0 for
    number, nil for pointer/map/slice, false for bool)
jasdel added a commit to jasdel/aws-sdk-go-v2 that referenced this issue Dec 9, 2020
Adds support for

* Fixes aws#895 - Add support for attribute value marshaling
* Fixes aws#929 - Support Number type aliases of string for support for
  json.Number like types.
* Fixes aws#115 - Simplifies the rules of `null` vs skipped vs zero value
  for all types.
  * All nil pointers, map, slice members are serialized as NULL.
  * omitempty struct tag skips zero value of members with the struct
    tag.
  * Empty and Nil Sets (NS, BS, SS) are serialized to null
    by default unless `NullEmptySets` EncoderOptions is set to false. True
    by default. Nil sets are always serialized as NULL, unless the
    `omitempty` struct tag is used.
  * Adds `nullempty` and `nullemptyelem` struct tags to direct if the
    encoder should marshal the member as a AttributeValue NULL if the
    member's value is the type's zero value, (e.g. "" for string, 0 for
    number, nil for pointer/map/slice, false for bool)
jasdel added a commit to jasdel/aws-sdk-go-v2 that referenced this issue Dec 11, 2020
Adds support for

* Fixes aws#895 - Add support for attribute value marshaling
* Fixes aws#929 - Support Number type aliases of string for support for
  json.Number like types.
* Fixes aws#115 - Simplifies the rules of `null` vs skipped vs zero value
  for all types.
  * All nil pointers, map, slice members are serialized as NULL.
  * omitempty struct tag skips zero value of members with the struct
    tag.
  * Empty and Nil Sets (NS, BS, SS) are serialized to null
    by default unless `NullEmptySets` EncoderOptions is set to false. True
    by default. Nil sets are always serialized as NULL, unless the
    `omitempty` struct tag is used.
  * Adds `nullempty` and `nullemptyelem` struct tags to direct if the
    encoder should marshal the member as a AttributeValue NULL if the
    member's value is the type's zero value, (e.g. "" for string, 0 for
    number, nil for pointer/map/slice, false for bool)
jasdel added a commit to jasdel/aws-sdk-go-v2 that referenced this issue Dec 14, 2020
Adds support for

* Fixes aws#895 - Add support for attribute value marshaling
* Fixes aws#929 - Support Number type aliases of string for support for
  json.Number like types.
* Fixes aws#115 - Simplifies the rules of `null` vs skipped vs zero value
  for all types.
  * All nil pointers, map, slice members are serialized as NULL.
  * omitempty struct tag skips zero value of members with the struct
    tag.
  * Empty and Nil Sets (NS, BS, SS) are serialized to null
    by default unless `NullEmptySets` EncoderOptions is set to false. True
    by default. Nil sets are always serialized as NULL, unless the
    `omitempty` struct tag is used.
  * Adds `nullempty` and `nullemptyelem` struct tags to direct if the
    encoder should marshal the member as a AttributeValue NULL if the
    member's value is the type's zero value, (e.g. "" for string, 0 for
    number, nil for pointer/map/slice, false for bool)
jasdel added a commit to jasdel/aws-sdk-go-v2 that referenced this issue Dec 15, 2020
Adds support for

* Fixes aws#895 - Add support for attribute value marshaling
* Fixes aws#929 - Support Number type aliases of string for support for
  json.Number like types.
* Fixes aws#115 - Simplifies the rules of `null` vs skipped vs zero value
  for all types.
  * All nil pointers, map, slice members are serialized as NULL.
  * omitempty struct tag skips zero value of members with the struct
    tag.
  * Empty and Nil Sets (NS, BS, SS) are serialized to null
    by default unless `NullEmptySets` EncoderOptions is set to false. True
    by default. Nil sets are always serialized as NULL, unless the
    `omitempty` struct tag is used.
  * Adds `nullempty` and `nullemptyelem` struct tags to direct if the
    encoder should marshal the member as a AttributeValue NULL if the
    member's value is the type's zero value, (e.g. "" for string, 0 for
    number, nil for pointer/map/slice, false for bool)
jasdel added a commit that referenced this issue Dec 15, 2020
…948)

Adds utilities for mapping Amazon DynamoDB API AttributeValue to and from Go types.

* Adds conversion util for DynamoDB  -> DynamoDBStreams AttributeValue.

* Fixes #895 -  Adds back marshaler/unmarshalers for attribute value to/from go types.
* Fixes #929 - Adds generic support for `json.Number` like types that are aliases of `string`s.
* Fixes #115 - Simplifies the rules of `null` vs skipped vs zero value
  for all types. 
  * All nil pointers, map, slice members are serialized as NULL AttributeValue.
  * `omitempty` struct tag skips zero value of members with the struct tag. `omitemptyelem` skips elements of list/map that have zero value. 
  * `nullempty` struct tag serializes zero value of members with the struct tag as NULL AttributeValue. `nullemptyelem` does same for elements of list/map that have zero value.
  * Empty and Nil Sets (NS, BS, SS) are serialized to null by default unless `NullEmptySets` EncoderOptions is set to false. True by default. Nil sets are always serialized as NULL, unless the`omitempty` struct tag is used.
  * Adds `nullempty` and `nullemptyelem` struct tags to direct if the encoder should marshal the member as a AttributeValue NULL if the member's value is the type's zero value, (e.g. "" for string, 0 for number, nil for pointer/map/slice, false for bool)
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automation-exempt feature-request A feature should be added or improved.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants