@@ -179,10 +179,115 @@ func Marshal(in interface{}) (types.AttributeValue, error) {
179179 return NewEncoder ().Encode (in )
180180}
181181
182+ // MarshalWithOptions will serialize the passed in Go value type into a AttributeValue
183+ // type, by using . This value can be used in API operations to simplify marshaling
184+ // your Go value types into AttributeValues.
185+ //
186+ // Use the `optsFns` functional options to override the default configuration.
187+ //
188+ // MarshalWithOptions will recursively transverse the passed in value marshaling its
189+ // contents into a AttributeValue. Marshal supports basic scalars
190+ // (int,uint,float,bool,string), maps, slices, and structs. Anonymous
191+ // nested types are flattened based on Go anonymous type visibility.
192+ //
193+ // Marshaling slices to AttributeValue will default to a List for all
194+ // types except for []byte and [][]byte. []byte will be marshaled as
195+ // Binary data (B), and [][]byte will be marshaled as binary data set
196+ // (BS).
197+ //
198+ // The `time.Time` type is marshaled as `time.RFC3339Nano` format.
199+ //
200+ // `dynamodbav` struct tag can be used to control how the value will be
201+ // marshaled into a AttributeValue.
202+ //
203+ // // Field is ignored
204+ // Field int `dynamodbav:"-"`
205+ //
206+ // // Field AttributeValue map key "myName"
207+ // Field int `dynamodbav:"myName"`
208+ //
209+ // // Field AttributeValue map key "myName", and
210+ // // Field is omitted if the field is a zero value for the type.
211+ // Field int `dynamodbav:"myName,omitempty"`
212+ //
213+ // // Field AttributeValue map key "Field", and
214+ // // Field is omitted if the field is a zero value for the type.
215+ // Field int `dynamodbav:",omitempty"`
216+ //
217+ // // Field's elems will be omitted if the elem's value is empty.
218+ // // only valid for slices, and maps.
219+ // Field []string `dynamodbav:",omitemptyelem"`
220+ //
221+ // // Field AttributeValue map key "Field", and
222+ // // Field is sent as NULL if the field is a zero value for the type.
223+ // Field int `dynamodbav:",nullempty"`
224+ //
225+ // // Field's elems will be sent as NULL if the elem's value a zero value
226+ // // for the type. Only valid for slices, and maps.
227+ // Field []string `dynamodbav:",nullemptyelem"`
228+ //
229+ // // Field will be marshaled as a AttributeValue string
230+ // // only value for number types, (int,uint,float)
231+ // Field int `dynamodbav:",string"`
232+ //
233+ // // Field will be marshaled as a binary set
234+ // Field [][]byte `dynamodbav:",binaryset"`
235+ //
236+ // // Field will be marshaled as a number set
237+ // Field []int `dynamodbav:",numberset"`
238+ //
239+ // // Field will be marshaled as a string set
240+ // Field []string `dynamodbav:",stringset"`
241+ //
242+ // // Field will be marshaled as Unix time number in seconds.
243+ // // This tag is only valid with time.Time typed struct fields.
244+ // // Important to note that zero value time as unixtime is not 0 seconds
245+ // // from January 1, 1970 UTC, but -62135596800. Which is seconds between
246+ // // January 1, 0001 UTC, and January 1, 0001 UTC.
247+ // Field time.Time `dynamodbav:",unixtime"`
248+ //
249+ // The omitempty tag is only used during Marshaling and is ignored for
250+ // Unmarshal. omitempty will skip any member if the Go value of the member is
251+ // zero. The omitemptyelem tag works the same as omitempty except it applies to
252+ // the elements of maps and slices instead of struct fields, and will not be
253+ // included in the marshaled AttributeValue Map, List, or Set.
254+ //
255+ // The nullempty tag is only used during Marshaling and is ignored for
256+ // Unmarshal. nullempty will serialize a AttributeValueMemberNULL for the
257+ // member if the Go value of the member is zero. nullemptyelem tag works the
258+ // same as nullempty except it applies to the elements of maps and slices
259+ // instead of struct fields, and will not be included in the marshaled
260+ // AttributeValue Map, List, or Set.
261+ //
262+ // All struct fields and with anonymous fields, are marshaled unless the
263+ // any of the following conditions are meet.
264+ //
265+ // - the field is not exported
266+ // - json or dynamodbav field tag is "-"
267+ // - json or dynamodbav field tag specifies "omitempty", and is a zero value.
268+ //
269+ // Pointer and interfaces values are encoded as the value pointed to or
270+ // contained in the interface. A nil value encodes as the AttributeValue NULL
271+ // value unless `omitempty` struct tag is provided.
272+ //
273+ // Channel, complex, and function values are not encoded and will be skipped
274+ // when walking the value to be marshaled.
275+ //
276+ // Error that occurs when marshaling will stop the marshal, and return
277+ // the error.
278+ //
279+ // MarshalWithOptions cannot represent cyclic data structures and will not handle them.
280+ // Passing cyclic structures to Marshal will result in an infinite recursion.
281+ func MarshalWithOptions (in interface {}, optFns ... func (* EncoderOptions )) (types.AttributeValue , error ) {
282+ return NewEncoder (optFns ... ).Encode (in )
283+ }
284+
182285// MarshalMap is an alias for Marshal func which marshals Go value type to a
183286// map of AttributeValues. If the in parameter does not serialize to a map, an
184287// empty AttributeValue map will be returned.
185288//
289+ // Use the `optsFns` functional options to override the default configuration.
290+ //
186291// This is useful for APIs such as PutItem.
187292func MarshalMap (in interface {}) (map [string ]types.AttributeValue , error ) {
188293 av , err := NewEncoder ().Encode (in )
@@ -195,6 +300,24 @@ func MarshalMap(in interface{}) (map[string]types.AttributeValue, error) {
195300 return asMap .Value , nil
196301}
197302
303+ // MarshalMapWithOptions is an alias for MarshalWithOptions func which marshals Go value type to a
304+ // map of AttributeValues. If the in parameter does not serialize to a map, an
305+ // empty AttributeValue map will be returned.
306+ //
307+ // Use the `optsFns` functional options to override the default configuration.
308+ //
309+ // This is useful for APIs such as PutItem.
310+ func MarshalMapWithOptions (in interface {}, optFns ... func (* EncoderOptions )) (map [string ]types.AttributeValue , error ) {
311+ av , err := NewEncoder (optFns ... ).Encode (in )
312+
313+ asMap , ok := av .(* types.AttributeValueMemberM )
314+ if err != nil || av == nil || ! ok {
315+ return map [string ]types.AttributeValue {}, err
316+ }
317+
318+ return asMap .Value , nil
319+ }
320+
198321// MarshalList is an alias for Marshal func which marshals Go value
199322// type to a slice of AttributeValues. If the in parameter does not serialize
200323// to a slice, an empty AttributeValue slice will be returned.
@@ -209,6 +332,22 @@ func MarshalList(in interface{}) ([]types.AttributeValue, error) {
209332 return asList .Value , nil
210333}
211334
335+ // MarshalListWithOptions is an alias for MarshalWithOptions func which marshals Go value
336+ // type to a slice of AttributeValues. If the in parameter does not serialize
337+ // to a slice, an empty AttributeValue slice will be returned.
338+ //
339+ // Use the `optsFns` functional options to override the default configuration.
340+ func MarshalListWithOptions (in interface {}, optFns ... func (* EncoderOptions )) ([]types.AttributeValue , error ) {
341+ av , err := NewEncoder (optFns ... ).Encode (in )
342+
343+ asList , ok := av .(* types.AttributeValueMemberL )
344+ if err != nil || av == nil || ! ok {
345+ return []types.AttributeValue {}, err
346+ }
347+
348+ return asList .Value , nil
349+ }
350+
212351// EncoderOptions is a collection of options shared between marshaling
213352// and unmarshaling
214353type EncoderOptions struct {
0 commit comments