Skip to content

Better nil support

Compare
Choose a tag to compare
@guregu guregu released this 15 Jul 22:56
· 187 commits to master since this release

This release fixes #99 by properly handling nil pointers of special encoders (such as TextMarshaler) whose encoding methods were on the value receiver. For example, *time.Time is now handled properly and will be automatically omitted if nil. Previously, it panicked.

Also, Update.Set now handles these properly by removing the given path. It does this for nil, nil pointers, and empty strings as well. However, if the nil pointer is a special encoder and its encoding method has a pointer receiver, it will not be removed. Previously, it erroneously returned an AWS SerializationException.

This means that instead of writing code like:

u := table.Update(...)
if someString == "" {
   u.Remove("SomeString")
} else {
   u.Set("SomeString", someString)
}

You may instead just write:

u.Set("SomeString", someString)

This changes Update to match its behavior with Put for automatically omitted attributes.