-
Notifications
You must be signed in to change notification settings - Fork 1
/
metered_component_unit_price.go
96 lines (82 loc) · 2.93 KB
/
metered_component_unit_price.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
/*
Package advancedbilling
This file was automatically generated for Maxio by APIMATIC v3.0 ( https://www.apimatic.io ).
*/
package models
import (
"encoding/json"
"errors"
"strings"
)
// MeteredComponentUnitPrice represents a MeteredComponentUnitPrice struct.
// This is a container for one-of cases.
type MeteredComponentUnitPrice struct {
value any
isString bool
isPrecision bool
}
// String converts the MeteredComponentUnitPrice object to a string representation.
func (m MeteredComponentUnitPrice) String() string {
if bytes, err := json.Marshal(m.value); err == nil {
return strings.Trim(string(bytes), "\"")
}
return ""
}
// MarshalJSON implements the json.Marshaler interface for MeteredComponentUnitPrice.
// It customizes the JSON marshaling process for MeteredComponentUnitPrice objects.
func (m MeteredComponentUnitPrice) MarshalJSON() (
[]byte,
error) {
if m.value == nil {
return nil, errors.New("No underlying type is set. Please use any of the `models.MeteredComponentUnitPriceContainer.From*` functions to initialize the MeteredComponentUnitPrice object.")
}
return json.Marshal(m.toMap())
}
// toMap converts the MeteredComponentUnitPrice object to a map representation for JSON marshaling.
func (m *MeteredComponentUnitPrice) toMap() any {
switch obj := m.value.(type) {
case *string:
return *obj
case *float64:
return *obj
}
return nil
}
// UnmarshalJSON implements the json.Unmarshaler interface for MeteredComponentUnitPrice.
// It customizes the JSON unmarshaling process for MeteredComponentUnitPrice objects.
func (m *MeteredComponentUnitPrice) UnmarshalJSON(input []byte) error {
result, err := UnmarshallOneOf(input,
NewTypeHolder(new(string), false, &m.isString),
NewTypeHolder(new(float64), false, &m.isPrecision),
)
m.value = result
return err
}
func (m *MeteredComponentUnitPrice) AsString() (
*string,
bool) {
if !m.isString {
return nil, false
}
return m.value.(*string), true
}
func (m *MeteredComponentUnitPrice) AsPrecision() (
*float64,
bool) {
if !m.isPrecision {
return nil, false
}
return m.value.(*float64), true
}
// internalMeteredComponentUnitPrice represents a meteredComponentUnitPrice struct.
// This is a container for one-of cases.
type internalMeteredComponentUnitPrice struct {}
var MeteredComponentUnitPriceContainer internalMeteredComponentUnitPrice
// The internalMeteredComponentUnitPrice instance, wrapping the provided string value.
func (m *internalMeteredComponentUnitPrice) FromString(val string) MeteredComponentUnitPrice {
return MeteredComponentUnitPrice{value: &val}
}
// The internalMeteredComponentUnitPrice instance, wrapping the provided float64 value.
func (m *internalMeteredComponentUnitPrice) FromPrecision(val float64) MeteredComponentUnitPrice {
return MeteredComponentUnitPrice{value: &val}
}