-
Notifications
You must be signed in to change notification settings - Fork 675
support for json to/from types.AttributeValue #3071
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
base: main
Are you sure you want to change the base?
Conversation
26d9d88
to
85cdf5a
Compare
85cdf5a
to
c87966c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly nitpicks, LGTM
if value != nil { | ||
jtv, ok := value.(bool) | ||
if !ok { | ||
return fmt.Errorf("expected NullAttributeValue to be of type *bool, got %T instead", value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] shouldn't this be just bool
?
|
||
shape, ok := value.([]interface{}) | ||
if !ok { | ||
return fmt.Errorf("unexpected JSON type %v", value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] can we also include what type we expected, like fmt.Errorf("expected a JSON list, got type %T val %v")
|
||
for key, value := range shape { | ||
var parsedVal types.AttributeValue | ||
mapVar := parsedVal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] I don't think this intermediate variable is necessary
name: "&types.AttributeValueMemberM", | ||
input: &types.AttributeValueMemberM{ | ||
Value: map[string]types.AttributeValue{ | ||
// we only use 1 key here because go does not guarantee key order and test will fail randomly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] We could also special case this and check against each key instead of just doing just string comparison, but this is fine as well
expected: `{"N":"123"}`, | ||
}, | ||
{ | ||
name: "&types.AttributeValueMemberN 2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some special cases on DynamoDB for small or huge numbers that I'd also like to see tested, like numbers larger than math.MaxInt64
. I'm sure current implementation would handle it, but it would give me peace of mind to have it explicitly tested
Implements the following functions for both
feature/dynamodb/attributevalue
andfeature/dynamodbstreams/attributevalue
to solve #2920 :func UnmarshalListJSON(data []byte) ([]types.AttributeValue, error) {
func UnmarshalMapJSON(data []byte) (map[string]types.AttributeValue, error) {
func UnmarshalJSON(data []byte) (types.AttributeValue, error) {
func MarshalListJSON(in []types.AttributeValue) ([]byte, error) {
func MarshalMapJSON(in map[string]types.AttributeValue) ([]byte, error) {
func MarshalJSON(in types.AttributeValue) ([]byte, error) {
Each package makes use of the correct
types
package (service/dynamodb/types
forfeature/dynamodb/attributevalue
andservice/dynamodbstreams/types
forfeature/dynamodbstreams/attributevalue
)