diff --git a/bool.go b/bool.go index b0d0432..fbc6f2b 100644 --- a/bool.go +++ b/bool.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-11-14 00:52:25.812586 +0000 UTC +// This file was generated by robots at 2018-12-06 14:29:53.447681 +0000 UTC package optional @@ -56,11 +56,16 @@ func (b Bool) MarshalJSON() ([]byte, error) { if b.Present() { return json.Marshal(b.value) } - var zero bool - return json.Marshal(zero) + return json.Marshal(nil) } func (b *Bool) UnmarshalJSON(data []byte) error { + + if string(data) == "null" { + b.value = nil + return nil + } + var value bool if err := json.Unmarshal(data, &value); err != nil { diff --git a/byte.go b/byte.go index d73e356..39409d8 100644 --- a/byte.go +++ b/byte.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-11-14 00:52:26.274563 +0000 UTC +// This file was generated by robots at 2018-12-06 14:29:53.79355 +0000 UTC package optional @@ -56,11 +56,16 @@ func (b Byte) MarshalJSON() ([]byte, error) { if b.Present() { return json.Marshal(b.value) } - var zero byte - return json.Marshal(zero) + return json.Marshal(nil) } func (b *Byte) UnmarshalJSON(data []byte) error { + + if string(data) == "null" { + b.value = nil + return nil + } + var value byte if err := json.Unmarshal(data, &value); err != nil { diff --git a/cmd/optional/main.go b/cmd/optional/main.go index 54b9dbe..0c8ce56 100644 --- a/cmd/optional/main.go +++ b/cmd/optional/main.go @@ -183,11 +183,16 @@ func ({{ .VariableName }} {{ .OutputName }}) MarshalJSON() ([]byte, error) { if {{ .VariableName }}.Present() { return json.Marshal({{ .VariableName }}.value) } - var zero {{ .TypeName }} - return json.Marshal(zero) + return json.Marshal(nil) } func ({{ .VariableName }} *{{ .OutputName }}) UnmarshalJSON(data []byte) error { + + if string(data) == "null" { + {{ .VariableName }}.value = nil + return nil + } + var value {{ .TypeName }} if err := json.Unmarshal(data, &value); err != nil { diff --git a/cmd/optional/testdata/optional_bar.go b/cmd/optional/testdata/optional_bar.go index 20ff0c8..01c9307 100644 --- a/cmd/optional/testdata/optional_bar.go +++ b/cmd/optional/testdata/optional_bar.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-11-14 00:54:14.621363 +0000 UTC +// This file was generated by robots at 2018-12-06 17:57:17.641444 +0000 UTC package bar @@ -56,11 +56,16 @@ func (o optionalBar) MarshalJSON() ([]byte, error) { if o.Present() { return json.Marshal(o.value) } - var zero bar - return json.Marshal(zero) + return json.Marshal(nil) } func (o *optionalBar) UnmarshalJSON(data []byte) error { + + if string(data) == "null" { + o.value = nil + return nil + } + var value bar if err := json.Unmarshal(data, &value); err != nil { diff --git a/cmd/optional/testdata/optional_foo.go b/cmd/optional/testdata/optional_foo.go index 667a74e..18a2c24 100644 --- a/cmd/optional/testdata/optional_foo.go +++ b/cmd/optional/testdata/optional_foo.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-11-14 00:54:14.61916 +0000 UTC +// This file was generated by robots at 2018-12-06 17:57:17.640425 +0000 UTC package foo @@ -56,11 +56,16 @@ func (o OptionalFoo) MarshalJSON() ([]byte, error) { if o.Present() { return json.Marshal(o.value) } - var zero Foo - return json.Marshal(zero) + return json.Marshal(nil) } func (o *OptionalFoo) UnmarshalJSON(data []byte) error { + + if string(data) == "null" { + o.value = nil + return nil + } + var value Foo if err := json.Unmarshal(data, &value); err != nil { diff --git a/cmd/optional/testdata/string.go b/cmd/optional/testdata/string.go index 44e2117..64074b9 100644 --- a/cmd/optional/testdata/string.go +++ b/cmd/optional/testdata/string.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-11-14 00:54:14.615858 +0000 UTC +// This file was generated by robots at 2018-12-06 17:57:17.639386 +0000 UTC package optional @@ -56,11 +56,16 @@ func (s String) MarshalJSON() ([]byte, error) { if s.Present() { return json.Marshal(s.value) } - var zero string - return json.Marshal(zero) + return json.Marshal(nil) } func (s *String) UnmarshalJSON(data []byte) error { + + if string(data) == "null" { + s.value = nil + return nil + } + var value string if err := json.Unmarshal(data, &value); err != nil { diff --git a/complex128.go b/complex128.go index e6954c3..b85dfbe 100644 --- a/complex128.go +++ b/complex128.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-11-14 00:52:26.694747 +0000 UTC +// This file was generated by robots at 2018-12-06 14:29:54.128811 +0000 UTC package optional @@ -56,11 +56,16 @@ func (c Complex128) MarshalJSON() ([]byte, error) { if c.Present() { return json.Marshal(c.value) } - var zero complex128 - return json.Marshal(zero) + return json.Marshal(nil) } func (c *Complex128) UnmarshalJSON(data []byte) error { + + if string(data) == "null" { + c.value = nil + return nil + } + var value complex128 if err := json.Unmarshal(data, &value); err != nil { diff --git a/complex64.go b/complex64.go index 4e011eb..04d5ee5 100644 --- a/complex64.go +++ b/complex64.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-11-14 00:52:27.082956 +0000 UTC +// This file was generated by robots at 2018-12-06 14:29:54.464548 +0000 UTC package optional @@ -56,11 +56,16 @@ func (c Complex64) MarshalJSON() ([]byte, error) { if c.Present() { return json.Marshal(c.value) } - var zero complex64 - return json.Marshal(zero) + return json.Marshal(nil) } func (c *Complex64) UnmarshalJSON(data []byte) error { + + if string(data) == "null" { + c.value = nil + return nil + } + var value complex64 if err := json.Unmarshal(data, &value); err != nil { diff --git a/error.go b/error.go index 41d3b7a..bc79ddc 100644 --- a/error.go +++ b/error.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-11-14 00:52:27.535329 +0000 UTC +// This file was generated by robots at 2018-12-06 14:29:54.804224 +0000 UTC package optional @@ -56,11 +56,16 @@ func (e Error) MarshalJSON() ([]byte, error) { if e.Present() { return json.Marshal(e.value) } - var zero error - return json.Marshal(zero) + return json.Marshal(nil) } func (e *Error) UnmarshalJSON(data []byte) error { + + if string(data) == "null" { + e.value = nil + return nil + } + var value error if err := json.Unmarshal(data, &value); err != nil { diff --git a/float32.go b/float32.go index eb78e2e..9f42c2c 100644 --- a/float32.go +++ b/float32.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-11-14 00:52:27.939662 +0000 UTC +// This file was generated by robots at 2018-12-06 14:29:55.1819 +0000 UTC package optional @@ -56,11 +56,16 @@ func (f Float32) MarshalJSON() ([]byte, error) { if f.Present() { return json.Marshal(f.value) } - var zero float32 - return json.Marshal(zero) + return json.Marshal(nil) } func (f *Float32) UnmarshalJSON(data []byte) error { + + if string(data) == "null" { + f.value = nil + return nil + } + var value float32 if err := json.Unmarshal(data, &value); err != nil { diff --git a/float64.go b/float64.go index 1125530..15966b6 100644 --- a/float64.go +++ b/float64.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-11-14 00:52:28.345245 +0000 UTC +// This file was generated by robots at 2018-12-06 14:29:55.521255 +0000 UTC package optional @@ -56,11 +56,16 @@ func (f Float64) MarshalJSON() ([]byte, error) { if f.Present() { return json.Marshal(f.value) } - var zero float64 - return json.Marshal(zero) + return json.Marshal(nil) } func (f *Float64) UnmarshalJSON(data []byte) error { + + if string(data) == "null" { + f.value = nil + return nil + } + var value float64 if err := json.Unmarshal(data, &value); err != nil { diff --git a/int.go b/int.go index f675e32..caead99 100644 --- a/int.go +++ b/int.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-11-14 00:52:28.766753 +0000 UTC +// This file was generated by robots at 2018-12-06 14:29:55.863991 +0000 UTC package optional @@ -56,11 +56,16 @@ func (i Int) MarshalJSON() ([]byte, error) { if i.Present() { return json.Marshal(i.value) } - var zero int - return json.Marshal(zero) + return json.Marshal(nil) } func (i *Int) UnmarshalJSON(data []byte) error { + + if string(data) == "null" { + i.value = nil + return nil + } + var value int if err := json.Unmarshal(data, &value); err != nil { diff --git a/int16.go b/int16.go index a6da247..9532996 100644 --- a/int16.go +++ b/int16.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-11-14 00:52:29.175694 +0000 UTC +// This file was generated by robots at 2018-12-06 14:29:56.212093 +0000 UTC package optional @@ -56,11 +56,16 @@ func (i Int16) MarshalJSON() ([]byte, error) { if i.Present() { return json.Marshal(i.value) } - var zero int16 - return json.Marshal(zero) + return json.Marshal(nil) } func (i *Int16) UnmarshalJSON(data []byte) error { + + if string(data) == "null" { + i.value = nil + return nil + } + var value int16 if err := json.Unmarshal(data, &value); err != nil { diff --git a/int32.go b/int32.go index f759790..07c212d 100644 --- a/int32.go +++ b/int32.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-11-14 00:52:29.586464 +0000 UTC +// This file was generated by robots at 2018-12-06 14:29:56.641482 +0000 UTC package optional @@ -56,11 +56,16 @@ func (i Int32) MarshalJSON() ([]byte, error) { if i.Present() { return json.Marshal(i.value) } - var zero int32 - return json.Marshal(zero) + return json.Marshal(nil) } func (i *Int32) UnmarshalJSON(data []byte) error { + + if string(data) == "null" { + i.value = nil + return nil + } + var value int32 if err := json.Unmarshal(data, &value); err != nil { diff --git a/int64.go b/int64.go index 0089cc3..7f8f01c 100644 --- a/int64.go +++ b/int64.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-11-14 00:52:30.027992 +0000 UTC +// This file was generated by robots at 2018-12-06 14:29:57.002648 +0000 UTC package optional @@ -56,11 +56,16 @@ func (i Int64) MarshalJSON() ([]byte, error) { if i.Present() { return json.Marshal(i.value) } - var zero int64 - return json.Marshal(zero) + return json.Marshal(nil) } func (i *Int64) UnmarshalJSON(data []byte) error { + + if string(data) == "null" { + i.value = nil + return nil + } + var value int64 if err := json.Unmarshal(data, &value); err != nil { diff --git a/int8.go b/int8.go index 4cdb349..182f814 100644 --- a/int8.go +++ b/int8.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-11-14 00:52:30.427813 +0000 UTC +// This file was generated by robots at 2018-12-06 14:29:57.555216 +0000 UTC package optional @@ -56,11 +56,16 @@ func (i Int8) MarshalJSON() ([]byte, error) { if i.Present() { return json.Marshal(i.value) } - var zero int8 - return json.Marshal(zero) + return json.Marshal(nil) } func (i *Int8) UnmarshalJSON(data []byte) error { + + if string(data) == "null" { + i.value = nil + return nil + } + var value int8 if err := json.Unmarshal(data, &value); err != nil { diff --git a/rune.go b/rune.go index a68653a..469de67 100644 --- a/rune.go +++ b/rune.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-11-14 00:52:30.867604 +0000 UTC +// This file was generated by robots at 2018-12-06 14:29:57.969673 +0000 UTC package optional @@ -56,11 +56,16 @@ func (r Rune) MarshalJSON() ([]byte, error) { if r.Present() { return json.Marshal(r.value) } - var zero rune - return json.Marshal(zero) + return json.Marshal(nil) } func (r *Rune) UnmarshalJSON(data []byte) error { + + if string(data) == "null" { + r.value = nil + return nil + } + var value rune if err := json.Unmarshal(data, &value); err != nil { diff --git a/string.go b/string.go index a346334..19e67c1 100644 --- a/string.go +++ b/string.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-11-14 00:52:31.29776 +0000 UTC +// This file was generated by robots at 2018-12-06 14:29:58.516631 +0000 UTC package optional @@ -56,11 +56,16 @@ func (s String) MarshalJSON() ([]byte, error) { if s.Present() { return json.Marshal(s.value) } - var zero string - return json.Marshal(zero) + return json.Marshal(nil) } func (s *String) UnmarshalJSON(data []byte) error { + + if string(data) == "null" { + s.value = nil + return nil + } + var value string if err := json.Unmarshal(data, &value); err != nil { diff --git a/uint.go b/uint.go index c9e610e..33e93e3 100644 --- a/uint.go +++ b/uint.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-11-14 00:52:31.699785 +0000 UTC +// This file was generated by robots at 2018-12-06 14:29:58.898667 +0000 UTC package optional @@ -56,11 +56,16 @@ func (u Uint) MarshalJSON() ([]byte, error) { if u.Present() { return json.Marshal(u.value) } - var zero uint - return json.Marshal(zero) + return json.Marshal(nil) } func (u *Uint) UnmarshalJSON(data []byte) error { + + if string(data) == "null" { + u.value = nil + return nil + } + var value uint if err := json.Unmarshal(data, &value); err != nil { diff --git a/uint16.go b/uint16.go index d7c7591..428ecbf 100644 --- a/uint16.go +++ b/uint16.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-11-14 00:52:32.12056 +0000 UTC +// This file was generated by robots at 2018-12-06 14:29:59.455534 +0000 UTC package optional @@ -56,11 +56,16 @@ func (u Uint16) MarshalJSON() ([]byte, error) { if u.Present() { return json.Marshal(u.value) } - var zero uint16 - return json.Marshal(zero) + return json.Marshal(nil) } func (u *Uint16) UnmarshalJSON(data []byte) error { + + if string(data) == "null" { + u.value = nil + return nil + } + var value uint16 if err := json.Unmarshal(data, &value); err != nil { diff --git a/uint32.go b/uint32.go index 125b416..5fa2ebf 100644 --- a/uint32.go +++ b/uint32.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-11-14 00:52:32.56791 +0000 UTC +// This file was generated by robots at 2018-12-06 14:29:59.856381 +0000 UTC package optional @@ -56,11 +56,16 @@ func (u Uint32) MarshalJSON() ([]byte, error) { if u.Present() { return json.Marshal(u.value) } - var zero uint32 - return json.Marshal(zero) + return json.Marshal(nil) } func (u *Uint32) UnmarshalJSON(data []byte) error { + + if string(data) == "null" { + u.value = nil + return nil + } + var value uint32 if err := json.Unmarshal(data, &value); err != nil { diff --git a/uint64.go b/uint64.go index 1252c06..f0d79a4 100644 --- a/uint64.go +++ b/uint64.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-11-14 00:52:32.98085 +0000 UTC +// This file was generated by robots at 2018-12-06 14:30:00.317311 +0000 UTC package optional @@ -56,11 +56,16 @@ func (u Uint64) MarshalJSON() ([]byte, error) { if u.Present() { return json.Marshal(u.value) } - var zero uint64 - return json.Marshal(zero) + return json.Marshal(nil) } func (u *Uint64) UnmarshalJSON(data []byte) error { + + if string(data) == "null" { + u.value = nil + return nil + } + var value uint64 if err := json.Unmarshal(data, &value); err != nil { diff --git a/uint8.go b/uint8.go index 920cb84..9b2be7f 100644 --- a/uint8.go +++ b/uint8.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-11-14 00:52:33.373985 +0000 UTC +// This file was generated by robots at 2018-12-06 14:30:00.699077 +0000 UTC package optional @@ -56,11 +56,16 @@ func (u Uint8) MarshalJSON() ([]byte, error) { if u.Present() { return json.Marshal(u.value) } - var zero uint8 - return json.Marshal(zero) + return json.Marshal(nil) } func (u *Uint8) UnmarshalJSON(data []byte) error { + + if string(data) == "null" { + u.value = nil + return nil + } + var value uint8 if err := json.Unmarshal(data, &value); err != nil { diff --git a/uintptr.go b/uintptr.go index b947661..af79fef 100644 --- a/uintptr.go +++ b/uintptr.go @@ -1,5 +1,5 @@ // Code generated by go generate -// This file was generated by robots at 2018-11-14 00:52:33.811844 +0000 UTC +// This file was generated by robots at 2018-12-06 14:30:01.109101 +0000 UTC package optional @@ -56,11 +56,16 @@ func (u Uintptr) MarshalJSON() ([]byte, error) { if u.Present() { return json.Marshal(u.value) } - var zero uintptr - return json.Marshal(zero) + return json.Marshal(nil) } func (u *Uintptr) UnmarshalJSON(data []byte) error { + + if string(data) == "null" { + u.value = nil + return nil + } + var value uintptr if err := json.Unmarshal(data, &value); err != nil {