From 96cabfe72a3119f65a0d8dfc68e412c2c86dca88 Mon Sep 17 00:00:00 2001 From: xengineering Date: Wed, 6 Nov 2024 21:07:45 +0100 Subject: REMOVE ME: playground: Implement Optional[T].MarshalJSON() --- playground/main.go | 10 ++++++++++ 1 file changed, 10 insertions(+) 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"` -- cgit v1.2.3-70-g09d2