-
Notifications
You must be signed in to change notification settings - Fork 1
/
invoice_custom_field.go
76 lines (69 loc) · 2.57 KB
/
invoice_custom_field.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
package models
import (
"encoding/json"
)
// InvoiceCustomField represents a InvoiceCustomField struct.
type InvoiceCustomField struct {
OwnerId *int `json:"owner_id,omitempty"`
OwnerType *CustomFieldOwner `json:"owner_type,omitempty"`
Name *string `json:"name,omitempty"`
Value *string `json:"value,omitempty"`
MetadatumId *int `json:"metadatum_id,omitempty"`
AdditionalProperties map[string]any `json:"_"`
}
// MarshalJSON implements the json.Marshaler interface for InvoiceCustomField.
// It customizes the JSON marshaling process for InvoiceCustomField objects.
func (i InvoiceCustomField) MarshalJSON() (
[]byte,
error) {
return json.Marshal(i.toMap())
}
// toMap converts the InvoiceCustomField object to a map representation for JSON marshaling.
func (i InvoiceCustomField) toMap() map[string]any {
structMap := make(map[string]any)
MapAdditionalProperties(structMap, i.AdditionalProperties)
if i.OwnerId != nil {
structMap["owner_id"] = i.OwnerId
}
if i.OwnerType != nil {
structMap["owner_type"] = i.OwnerType
}
if i.Name != nil {
structMap["name"] = i.Name
}
if i.Value != nil {
structMap["value"] = i.Value
}
if i.MetadatumId != nil {
structMap["metadatum_id"] = i.MetadatumId
}
return structMap
}
// UnmarshalJSON implements the json.Unmarshaler interface for InvoiceCustomField.
// It customizes the JSON unmarshaling process for InvoiceCustomField objects.
func (i *InvoiceCustomField) UnmarshalJSON(input []byte) error {
var temp invoiceCustomField
err := json.Unmarshal(input, &temp)
if err != nil {
return err
}
additionalProperties, err := UnmarshalAdditionalProperties(input, "owner_id", "owner_type", "name", "value", "metadatum_id")
if err != nil {
return err
}
i.AdditionalProperties = additionalProperties
i.OwnerId = temp.OwnerId
i.OwnerType = temp.OwnerType
i.Name = temp.Name
i.Value = temp.Value
i.MetadatumId = temp.MetadatumId
return nil
}
// invoiceCustomField is a temporary struct used for validating the fields of InvoiceCustomField.
type invoiceCustomField struct {
OwnerId *int `json:"owner_id,omitempty"`
OwnerType *CustomFieldOwner `json:"owner_type,omitempty"`
Name *string `json:"name,omitempty"`
Value *string `json:"value,omitempty"`
MetadatumId *int `json:"metadatum_id,omitempty"`
}