-
Notifications
You must be signed in to change notification settings - Fork 1
/
product_family.go
110 lines (103 loc) · 3.74 KB
/
product_family.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
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 models
import (
"encoding/json"
"log"
"time"
)
// ProductFamily represents a ProductFamily struct.
type ProductFamily struct {
Id *int `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
Handle *string `json:"handle,omitempty"`
AccountingCode Optional[string] `json:"accounting_code"`
Description Optional[string] `json:"description"`
CreatedAt *time.Time `json:"created_at,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
AdditionalProperties map[string]any `json:"_"`
}
// MarshalJSON implements the json.Marshaler interface for ProductFamily.
// It customizes the JSON marshaling process for ProductFamily objects.
func (p ProductFamily) MarshalJSON() (
[]byte,
error) {
return json.Marshal(p.toMap())
}
// toMap converts the ProductFamily object to a map representation for JSON marshaling.
func (p ProductFamily) toMap() map[string]any {
structMap := make(map[string]any)
MapAdditionalProperties(structMap, p.AdditionalProperties)
if p.Id != nil {
structMap["id"] = p.Id
}
if p.Name != nil {
structMap["name"] = p.Name
}
if p.Handle != nil {
structMap["handle"] = p.Handle
}
if p.AccountingCode.IsValueSet() {
if p.AccountingCode.Value() != nil {
structMap["accounting_code"] = p.AccountingCode.Value()
} else {
structMap["accounting_code"] = nil
}
}
if p.Description.IsValueSet() {
if p.Description.Value() != nil {
structMap["description"] = p.Description.Value()
} else {
structMap["description"] = nil
}
}
if p.CreatedAt != nil {
structMap["created_at"] = p.CreatedAt.Format(time.RFC3339)
}
if p.UpdatedAt != nil {
structMap["updated_at"] = p.UpdatedAt.Format(time.RFC3339)
}
return structMap
}
// UnmarshalJSON implements the json.Unmarshaler interface for ProductFamily.
// It customizes the JSON unmarshaling process for ProductFamily objects.
func (p *ProductFamily) UnmarshalJSON(input []byte) error {
var temp productFamily
err := json.Unmarshal(input, &temp)
if err != nil {
return err
}
additionalProperties, err := UnmarshalAdditionalProperties(input, "id", "name", "handle", "accounting_code", "description", "created_at", "updated_at")
if err != nil {
return err
}
p.AdditionalProperties = additionalProperties
p.Id = temp.Id
p.Name = temp.Name
p.Handle = temp.Handle
p.AccountingCode = temp.AccountingCode
p.Description = temp.Description
if temp.CreatedAt != nil {
CreatedAtVal, err := time.Parse(time.RFC3339, *temp.CreatedAt)
if err != nil {
log.Fatalf("Cannot Parse created_at as % s format.", time.RFC3339)
}
p.CreatedAt = &CreatedAtVal
}
if temp.UpdatedAt != nil {
UpdatedAtVal, err := time.Parse(time.RFC3339, *temp.UpdatedAt)
if err != nil {
log.Fatalf("Cannot Parse updated_at as % s format.", time.RFC3339)
}
p.UpdatedAt = &UpdatedAtVal
}
return nil
}
// productFamily is a temporary struct used for validating the fields of ProductFamily.
type productFamily struct {
Id *int `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
Handle *string `json:"handle,omitempty"`
AccountingCode Optional[string] `json:"accounting_code"`
Description Optional[string] `json:"description"`
CreatedAt *string `json:"created_at,omitempty"`
UpdatedAt *string `json:"updated_at,omitempty"`
}