-
Notifications
You must be signed in to change notification settings - Fork 0
/
marshals.gno
110 lines (79 loc) · 1.73 KB
/
marshals.gno
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package zentasktic_user
import (
"strconv"
"bytes"
"errors"
"std"
)
type UsersObject struct {
Users []User
}
type PaymentsObject struct {
Payments []*Payment
}
func (u User) MarshalJSON() ([]byte, error) {
var b bytes.Buffer
b.WriteByte('{')
b.WriteString(`"usereId":"`)
b.WriteString(u.Id)
b.WriteString(`",`)
b.WriteString(`"userName":"`)
b.WriteString(u.Name)
b.WriteString(`",`)
b.WriteString(`"userAddress":"`)
b.WriteString(string(u.Address))
b.WriteString(`"`)
b.WriteByte('}')
return b.Bytes(), nil
}
func (uo UsersObject) MarshalJSON() ([]byte, error) {
var b bytes.Buffer
b.WriteString(`{"users":[`)
for i, user := range uo.Users {
if i > 0 {
b.WriteString(`,`)
}
userJSON, cerr := user.MarshalJSON()
if cerr == nil {
b.WriteString(string(userJSON))
}
}
b.WriteString(`]}`)
return b.Bytes(), nil
}
func (p Payment) MarshalJSON() ([]byte, error) {
var b bytes.Buffer
b.WriteByte('{')
b.WriteString(`"paymentId":"`)
b.WriteString(p.Id)
b.WriteString(`",`)
b.WriteString(`"objectId":"`)
b.WriteString(p.ObjectId)
b.WriteString(`",`)
b.WriteString(`"objectType":"`)
b.WriteString(p.ObjectType)
b.WriteString(`",`)
b.WriteString(`"paymentAmount":"`)
b.WriteString(string(p.Amount.String()))
b.WriteString(`",`)
b.WriteString(`"paymentStatus":"`)
b.WriteString(p.Status)
b.WriteString(`"`)
b.WriteByte('}')
return b.Bytes(), nil
}
func (po PaymentsObject) MarshalJSON() ([]byte, error) {
var b bytes.Buffer
b.WriteString(`{"payments":[`)
for i, payment := range po.Payments {
if i > 0 {
b.WriteString(`,`)
}
paymentsJSON, cerr := payment.MarshalJSON()
if cerr == nil {
b.WriteString(string(paymentsJSON))
}
}
b.WriteString(`]}`)
return b.Bytes(), nil
}