Skip to content

@guregu guregu released this Aug 9, 2020 · 3 commits to master since this release

This release improves and extends many areas of the encoder, improving support for empty and null values and fixing some important issues.
We can now take advantage of DynamoDB's support for empty strings and binary attributes!

  • Added support for empty/null values in DynamoDB lists (slices and arrays) and sets (slices or maps with the dynamo:",set" struct tag option). By default, empty strings and binary values are encoded as-is, and nil pointers are set to a DynamoDB NULL type. Previously these cases were a SerializationException. Fixes #102 and #137.
    • Added a new struct tag option dynamo:",omitemptyelem" that omits these values instead. Note that this will mess up your array indexes.
  • Added a new struct tag option dynamo:",allowempty" to disable auto-omit behavior for empty string or binary field values. Keep in mind that primary keys can't be empty.
  • Added a new struct tag option dynamo:",allowemptyelem" to disable auto-omit behavior for empty string, empty binary, and nil values in maps.
  • Added a new struct tag option dynamo:",null" that will marshal nil or empty values to DynamoDB NULL types. When allowempty is also set, allowempty will take precedence.
  • Added Update.SetNullable which is Update.Set without automatic empty/nil removal.
  • Added support for empty/nil arguments in If and Filter.
  • Added support for custom empty structs in sets: #133, thanks @finnbear.
  • Docs improvements: #123, #136. Thanks @ZacharyGroff and @d-tsuji.

This release should have total backwards compatibility with previous versions. New support for empty/nil values was added in areas that were previously serialization errors. Auto-omit behavior was kept the same, but now you can use allowempty and allowemptyelem to disable it.

Example:

var widget = struct {
	HashKey string
	Desc    string `dynamo:",allowempty"`
	Words   []string
	Ptr     *int `dynamo:",null"`
}{
	HashKey: "abc",
	Desc:    "",
	Words:   []string{"hello", "world", ""},
	Ptr:     nil,
}

will be marshaled like so

{
	HashKey: {S: "abc"},
	Desc: {S: ""},
	Words: {L: [{S: "hello"}, {S: "world"} {S: ""}]},
	Ptr: {NULL: true},
}

Big thanks to everyone who submitted issues and PRs, and all the users of this library.

Assets 2
You can’t perform that action at this time.