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: Add utility to (un)marshal Attribtue Values #948

Merged
merged 9 commits into from
Dec 15, 2020

Conversation

jasdel
Copy link
Contributor

@jasdel jasdel commented Dec 4, 2020

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

  • Adds conversion util for DynamoDB -> DynamoDBStreams AttributeValue.

  • Fixes dynamodb/attributevalue: Add AttributeValue marshaler utilities #895 - Adds back marshaler/unmarshalers for attribute value to/from go types.

  • Fixes dynamodb/attributevalue: Marshal does not support json.Number to Numeric data type #929 - Adds generic support for json.Number like types that are aliases of strings.

  • Fixes dynamodb/attributevalue: Consider changing default behavior for empty maps and slices #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 theomitempty 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)

TODO:

  • Duplicate behavior for DynamoDB Streams
  • Update docs
  • add changelog

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)
Comment on lines +170 to +171
_, isNull := av.(*types.AttributeValueMemberNULL)
if av == nil || isNull {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If av is not nil and the type is AttributeValueMemberNULL should this check that av.Value == true?

Copy link
Member

@skmcgrail skmcgrail Dec 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be odd if it was set to false, but it's the more correct check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could check if Value is false. I'll check if Dynamo looks at this value. I had a feeling it ignored or always set the value to true on its side. A value of false doesn't really have any clear meaning. (Other than potentially error)

@skmcgrail skmcgrail self-requested a review December 15, 2020 01:11
@jasdel jasdel merged commit bb7c602 into aws:master Dec 15, 2020
@jasdel jasdel deleted the ddbAttrib branch December 15, 2020 22:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants