Skip to content

Commit

Permalink
service/dynamodb/dynamodbattribute: Support for configuring the marsh…
Browse files Browse the repository at this point in the history
…alling behavior of empty collections
  • Loading branch information
skmcgrail committed Sep 24, 2019
1 parent 2d3575f commit 716a0d4
Show file tree
Hide file tree
Showing 3 changed files with 702 additions and 18 deletions.
16 changes: 9 additions & 7 deletions service/dynamodb/dynamodbattribute/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strconv"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/dynamodb"
)

Expand Down Expand Up @@ -155,6 +156,7 @@ var byteSliceType = reflect.TypeOf([]byte(nil))
var byteSliceSlicetype = reflect.TypeOf([][]byte(nil))
var numberType = reflect.TypeOf(Number(""))
var timeType = reflect.TypeOf(time.Time{})
var ptrStringType = reflect.TypeOf(aws.String(""))

func (d *Decoder) decode(av *dynamodb.AttributeValue, v reflect.Value, fieldTag tag) error {
var u Unmarshaler
Expand All @@ -172,23 +174,23 @@ func (d *Decoder) decode(av *dynamodb.AttributeValue, v reflect.Value, fieldTag
}

switch {
case len(av.B) != 0:
case len(av.B) != 0 || (av.B != nil && d.EnableEmptyCollections):
return d.decodeBinary(av.B, v)
case av.BOOL != nil:
return d.decodeBool(av.BOOL, v)
case len(av.BS) != 0:
case len(av.BS) != 0 || (av.BS != nil && d.EnableEmptyCollections):
return d.decodeBinarySet(av.BS, v)
case len(av.L) != 0:
case len(av.L) != 0 || (av.L != nil && d.EnableEmptyCollections):
return d.decodeList(av.L, v)
case len(av.M) != 0:
case len(av.M) != 0 || (av.M != nil && d.EnableEmptyCollections):
return d.decodeMap(av.M, v)
case av.N != nil:
return d.decodeNumber(av.N, v, fieldTag)
case len(av.NS) != 0:
case len(av.NS) != 0 || (av.NS != nil && d.EnableEmptyCollections):
return d.decodeNumberSet(av.NS, v)
case av.S != nil:
case av.S != nil: // DynamoDB does not allow for empty strings, so we do not consider the length or EnableEmptyCollections flag here
return d.decodeString(av.S, v, fieldTag)
case len(av.SS) != 0:
case len(av.SS) != 0 || (av.SS != nil && d.EnableEmptyCollections):
return d.decodeStringSet(av.SS, v)
}

Expand Down
Loading

0 comments on commit 716a0d4

Please sign in to comment.