diff options
-rw-r--r-- | playground/main.go | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/playground/main.go b/playground/main.go index 8c67cc0..8487c5b 100644 --- a/playground/main.go +++ b/playground/main.go @@ -33,6 +33,16 @@ func (o *Optional[T]) UnmarshalJSON(data []byte) error { return nil } +func (o Optional[T]) MarshalJSON() ([]byte, error) { + var Temp *T + + if o.Exists { + Temp = &o.Value + } + + return json.Marshal(Temp) +} + type Testy struct { Flag *bool `json:"flag"` Cake *[]string `json:"cake"` |