summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2024-11-06 21:07:45 +0100
committerxengineering <me@xengineering.eu>2024-11-06 21:07:45 +0100
commit96cabfe72a3119f65a0d8dfc68e412c2c86dca88 (patch)
tree801d87404583b516d3b567245f9ced19ebc2c124
parent4c21918d28a01cf8819239dad4869ae49461292e (diff)
downloadceres-96cabfe72a3119f65a0d8dfc68e412c2c86dca88.tar
ceres-96cabfe72a3119f65a0d8dfc68e412c2c86dca88.tar.zst
ceres-96cabfe72a3119f65a0d8dfc68e412c2c86dca88.zip
REMOVE ME: playground: Implement Optional[T].MarshalJSON()
-rw-r--r--playground/main.go10
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"`