Skip to content

Instantly share code, notes, and snippets.

@bradclawsie
Created June 5, 2013 05:37
Show Gist options
  • Save bradclawsie/5711821 to your computer and use it in GitHub Desktop.
Save bradclawsie/5711821 to your computer and use it in GitHub Desktop.
some "nullable" base types for go
type NullableString string
func (n NullableString) MarshalJSON() ([]byte, error) {
sn := string(n)
if sn == "" {
var i interface{}
return json.Marshal(i)
}
return json.Marshal(sn)
}
type NullableUInt64 uint64
func (n NullableUInt64) MarshalJSON() ([]byte, error) {
in := uint64(n)
if in == 0 {
var i interface{}
return json.Marshal(i)
}
return json.Marshal(in)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment