Description

Marshal will serialize the passed in Go value type into a DynamoDB AttributeValue type. This value can be used in DynamoDB API operations to simplify marshaling your Go value types into AttributeValues.

Marshal will recursively transverse the passed in value marshaling its contents into a AttributeValue. Marshal supports basic scalars (int,uint,float,bool,string), maps, slices, and structs. Anonymous nested types are flattened based on Go anonymous type visibility.

Marshaling slices to AttributeValue will default to a List for all types except for []byte and [][]byte. []byte will be marshaled as Binary data (B), and [][]byte will be marshaled as binary data set (BS).

`dynamodbav` struct tag can be used to control how the value will be marshaled into a AttributeValue.

// Field is ignored
Field int `dynamodbav:"-"`

// Field AttributeValue map key "myName"
Field int `dynamodbav:"myName"`

// Field AttributeValue map key "myName", and
// Field is omitted if it is empty
Field int `dynamodbav:"myName,omitempty"`

// Field AttributeValue map key "Field", and
// Field is omitted if it is empty
Field int `dynamodbav:",omitempty"`

// Field's elems will be omitted if empty
// only valid for slices, and maps.
Field []string `dynamodbav:",omitemptyelem"`

// Field will be marshaled as a AttributeValue string
// only value for number types, (int,uint,float)
Field int `dynamodbav:",string"`

// Field will be marshaled as a binary set
Field [][]byte `dynamodbav:",binaryset"`

// Field will be marshaled as a number set
Field []int `dynamodbav:",numberset"`

// Field will be marshaled as a string set
Field []string `dynamodbav:",stringset"`

The omitempty tag is only used during Marshaling and is ignored for Unmarshal. Any zero value or a value when marshaled results in a AttributeValue NULL will be added to AttributeValue Maps during struct marshal. The omitemptyelem tag works the same as omitempty except it applies to maps and slices instead of struct fields, and will not be included in the marshaled AttributeValue Map, List, or Set.

For convenience and backwards compatibility with ConvertTo functions json struct tags are supported by the Marshal and Unmarshal. If both json and dynamodbav struct tags are provided the json tag will be ignored in favor of dynamodbav.

All struct fields and with anonymous fields, are marshaled unless the any of the following conditions are meet.

- the field is not exported
- json or dynamodbav field tag is "-"
- json or dynamodbav field tag specifies "omitempty", and is empty.

Pointer and interfaces values encode as the value pointed to or contained in the interface. A nil value encodes as the AttributeValue NULL value.

Channel, complex, and function values are not encoded and will be skipped when walking the value to be marshaled.

When marshaling any error that occurs will halt the marshal and return the error.

Marshal cannot represent cyclic data structures and will not handle them. Passing cyclic structures to Marshal will result in an infinite recursion.