/
zz_generated_models_serde.go
116 lines (106 loc) · 3.79 KB
/
zz_generated_models_serde.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
111
112
113
114
115
116
//go:build go1.18
// +build go1.18
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// Code generated by Microsoft (R) AutoRest Code Generator.
// Changes may cause incorrect behavior and will be lost if the code is regenerated.
package armdashboard
import (
"encoding/json"
"fmt"
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"reflect"
)
// MarshalJSON implements the json.Marshaller interface for type ManagedGrafana.
func (m ManagedGrafana) MarshalJSON() ([]byte, error) {
objectMap := make(map[string]interface{})
populate(objectMap, "id", m.ID)
populate(objectMap, "identity", m.Identity)
populate(objectMap, "location", m.Location)
populate(objectMap, "name", m.Name)
populate(objectMap, "properties", m.Properties)
populate(objectMap, "sku", m.SKU)
populate(objectMap, "systemData", m.SystemData)
populate(objectMap, "tags", m.Tags)
populate(objectMap, "type", m.Type)
return json.Marshal(objectMap)
}
// MarshalJSON implements the json.Marshaller interface for type ManagedGrafanaUpdateParameters.
func (m ManagedGrafanaUpdateParameters) MarshalJSON() ([]byte, error) {
objectMap := make(map[string]interface{})
populate(objectMap, "identity", m.Identity)
populate(objectMap, "tags", m.Tags)
return json.Marshal(objectMap)
}
// MarshalJSON implements the json.Marshaller interface for type ManagedIdentity.
func (m ManagedIdentity) MarshalJSON() ([]byte, error) {
objectMap := make(map[string]interface{})
populate(objectMap, "principalId", m.PrincipalID)
populate(objectMap, "tenantId", m.TenantID)
populate(objectMap, "type", m.Type)
populate(objectMap, "userAssignedIdentities", m.UserAssignedIdentities)
return json.Marshal(objectMap)
}
// MarshalJSON implements the json.Marshaller interface for type SystemData.
func (s SystemData) MarshalJSON() ([]byte, error) {
objectMap := make(map[string]interface{})
populateTimeRFC3339(objectMap, "createdAt", s.CreatedAt)
populate(objectMap, "createdBy", s.CreatedBy)
populate(objectMap, "createdByType", s.CreatedByType)
populateTimeRFC3339(objectMap, "lastModifiedAt", s.LastModifiedAt)
populate(objectMap, "lastModifiedBy", s.LastModifiedBy)
populate(objectMap, "lastModifiedByType", s.LastModifiedByType)
return json.Marshal(objectMap)
}
// UnmarshalJSON implements the json.Unmarshaller interface for type SystemData.
func (s *SystemData) UnmarshalJSON(data []byte) error {
var rawMsg map[string]json.RawMessage
if err := json.Unmarshal(data, &rawMsg); err != nil {
return fmt.Errorf("unmarshalling type %T: %v", s, err)
}
for key, val := range rawMsg {
var err error
switch key {
case "createdAt":
err = unpopulateTimeRFC3339(val, "CreatedAt", &s.CreatedAt)
delete(rawMsg, key)
case "createdBy":
err = unpopulate(val, "CreatedBy", &s.CreatedBy)
delete(rawMsg, key)
case "createdByType":
err = unpopulate(val, "CreatedByType", &s.CreatedByType)
delete(rawMsg, key)
case "lastModifiedAt":
err = unpopulateTimeRFC3339(val, "LastModifiedAt", &s.LastModifiedAt)
delete(rawMsg, key)
case "lastModifiedBy":
err = unpopulate(val, "LastModifiedBy", &s.LastModifiedBy)
delete(rawMsg, key)
case "lastModifiedByType":
err = unpopulate(val, "LastModifiedByType", &s.LastModifiedByType)
delete(rawMsg, key)
}
if err != nil {
return fmt.Errorf("unmarshalling type %T: %v", s, err)
}
}
return nil
}
func populate(m map[string]interface{}, k string, v interface{}) {
if v == nil {
return
} else if azcore.IsNullValue(v) {
m[k] = nil
} else if !reflect.ValueOf(v).IsNil() {
m[k] = v
}
}
func unpopulate(data json.RawMessage, fn string, v interface{}) error {
if data == nil {
return nil
}
if err := json.Unmarshal(data, v); err != nil {
return fmt.Errorf("struct field %s: %v", fn, err)
}
return nil
}