aboutsummaryrefslogtreecommitdiff
path: root/refined/struct.go
diff options
context:
space:
mode:
Diffstat (limited to 'refined/struct.go')
-rw-r--r--refined/struct.go24
1 files changed, 20 insertions, 4 deletions
diff --git a/refined/struct.go b/refined/struct.go
index 35a0c85..ee34f0f 100644
--- a/refined/struct.go
+++ b/refined/struct.go
@@ -3,10 +3,26 @@
package refined
-type Struct[P any] struct {
- Has P
+import "encoding/json"
+
+type Struct[T any] struct {
+ Has T
+}
+
+func NewStruct[T any](attributes T) Struct[T] {
+ return Struct[T]{Has: attributes}
}
-func NewStruct[P any](payload P) Struct[P] {
- return Struct[P]{Has: payload}
+func (s Struct[T]) MarshalJSON() ([]byte, error) {
+ return json.Marshal(s.Has)
+}
+
+func (s *Struct[T]) UnmarshalJSON(buf []byte) error {
+ err := json.Unmarshal(buf, &s.Has)
+ if err != nil {
+ return err
+ }
+
+ // TODO reflect on the fields of s.Has; if any are refined.Value that are not occupied, attempt to fill the zero value through Refine()
+ return nil
}