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 23, 2019
1 parent 2d3575f commit f414792
Show file tree
Hide file tree
Showing 3 changed files with 701 additions and 17 deletions.
14 changes: 8 additions & 6 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.EmptyCollections):
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.EmptyCollections):
return d.decodeBinarySet(av.BS, v)
case len(av.L) != 0:
case len(av.L) != 0 || (av.L != nil && d.EmptyCollections):
return d.decodeList(av.L, v)
case len(av.M) != 0:
case len(av.M) != 0 || (av.M != nil && d.EmptyCollections):
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.EmptyCollections):
return d.decodeNumberSet(av.NS, v)
case av.S != nil:
return d.decodeString(av.S, v, fieldTag)
case len(av.SS) != 0:
case len(av.SS) != 0 || (av.SS != nil && d.EmptyCollections):
return d.decodeStringSet(av.SS, v)
}

Expand Down
Loading

0 comments on commit f414792

Please sign in to comment.