forked from pagarme/pagarme-golang-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getOrderItemResponse.go
69 lines (62 loc) · 1.75 KB
/
getOrderItemResponse.go
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
package models
import (
"encoding/json"
"github.com/apimatic/go-core-runtime/types"
)
// Response object for getting an order item
type GetOrderItemResponse struct {
Id types.Optional[string] `json:"id"`
Amount types.Optional[int] `json:"amount"`
Description types.Optional[string] `json:"description"`
Quantity types.Optional[int] `json:"quantity"`
Category types.Optional[string] `json:"category"`
Code types.Optional[string] `json:"code"`
}
func (g *GetOrderItemResponse) MarshalJSON() (
[]byte,
error) {
return json.Marshal(g.toMap())
}
func (g *GetOrderItemResponse) toMap() map[string]any {
structMap := make(map[string]any)
if g.Id.IsValueSet() {
structMap["id"] = g.Id.Value()
}
if g.Amount.IsValueSet() {
structMap["amount"] = g.Amount.Value()
}
if g.Description.IsValueSet() {
structMap["description"] = g.Description.Value()
}
if g.Quantity.IsValueSet() {
structMap["quantity"] = g.Quantity.Value()
}
if g.Category.IsValueSet() {
structMap["category"] = g.Category.Value()
}
if g.Code.IsValueSet() {
structMap["code"] = g.Code.Value()
}
return structMap
}
func (g *GetOrderItemResponse) UnmarshalJSON(input []byte) error {
temp := &struct {
Id types.Optional[string] `json:"id"`
Amount types.Optional[int] `json:"amount"`
Description types.Optional[string] `json:"description"`
Quantity types.Optional[int] `json:"quantity"`
Category types.Optional[string] `json:"category"`
Code types.Optional[string] `json:"code"`
}{}
err := json.Unmarshal(input, &temp)
if err != nil {
return err
}
g.Id = temp.Id
g.Amount = temp.Amount
g.Description = temp.Description
g.Quantity = temp.Quantity
g.Category = temp.Category
g.Code = temp.Code
return nil
}