diff options
author | xengineering <me@xengineering.eu> | 2024-11-06 21:07:45 +0100 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2024-11-06 21:07:45 +0100 |
commit | 96cabfe72a3119f65a0d8dfc68e412c2c86dca88 (patch) | |
tree | 801d87404583b516d3b567245f9ced19ebc2c124 /playground/main.go | |
parent | 4c21918d28a01cf8819239dad4869ae49461292e (diff) | |
download | ceres-96cabfe72a3119f65a0d8dfc68e412c2c86dca88.tar ceres-96cabfe72a3119f65a0d8dfc68e412c2c86dca88.tar.zst ceres-96cabfe72a3119f65a0d8dfc68e412c2c86dca88.zip |
REMOVE ME: playground: Implement Optional[T].MarshalJSON()
Diffstat (limited to 'playground/main.go')
-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"` |