go-artifactory
go-artifactory copied to clipboard
Omitempty marshalling
Quick note on using omit empty in the structs for requests.
The "omitempty" option specifies that the field should be omitted from the encoding if the field has an empty value, defined as false, 0, a nil pointer, a nil interface value, and any empty array, slice, map, or string.
This makes it impossible to zero a value in a request as they are always excluded meaning a boolean can never be set to false or strings never set to empty. (This is also true for the new branch).
I have encountered this issue in writing a terraform provider as often time fields that are empty do need to be omitted as they shouldn't update remotely, requests should only include the relevant fields but there are times when a property needs to be zeroed. If the omit empty is removed then every single field will need to be set to the correct value which is verbose and impractical.
As far as I know the only fix for this is to store all the struct fields as pointers which allows for a distinction between null and zero.
Example is: https://github.com/google/go-github/blob/master/github/repos.go