-
Notifications
You must be signed in to change notification settings - Fork 0
/
model_serde_gen.go
99 lines (96 loc) · 2.84 KB
/
model_serde_gen.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
// Code generated by mkunion. DO NOT EDIT.
package schema
import (
"encoding/json"
"fmt"
"github.com/widmogrod/mkunion/x/shared"
)
var (
_ json.Unmarshaler = (*Field)(nil)
_ json.Marshaler = (*Field)(nil)
)
func (r *Field) MarshalJSON() ([]byte, error) {
if r == nil {
return nil, nil
}
return r._marshalJSONField(*r)
}
func (r *Field) _marshalJSONField(x Field) ([]byte, error) {
partial := make(map[string]json.RawMessage)
var err error
var fieldName []byte
fieldName, err = r._marshalJSONstring(x.Name)
if err != nil {
return nil, fmt.Errorf("schema: Field._marshalJSONField: field name Name; %w", err)
}
partial["Name"] = fieldName
var fieldValue []byte
fieldValue, err = r._marshalJSONSchema(x.Value)
if err != nil {
return nil, fmt.Errorf("schema: Field._marshalJSONField: field name Value; %w", err)
}
partial["Value"] = fieldValue
result, err := json.Marshal(partial)
if err != nil {
return nil, fmt.Errorf("schema: Field._marshalJSONField: struct; %w", err)
}
return result, nil
}
func (r *Field) _marshalJSONstring(x string) ([]byte, error) {
result, err := json.Marshal(x)
if err != nil {
return nil, fmt.Errorf("schema: Field._marshalJSONstring:; %w", err)
}
return result, nil
}
func (r *Field) _marshalJSONSchema(x Schema) ([]byte, error) {
result, err := shared.JSONMarshal[Schema](x)
if err != nil {
return nil, fmt.Errorf("schema: Field._marshalJSONSchema:; %w", err)
}
return result, nil
}
func (r *Field) UnmarshalJSON(data []byte) error {
result, err := r._unmarshalJSONField(data)
if err != nil {
return fmt.Errorf("schema: Field.UnmarshalJSON: %w", err)
}
*r = result
return nil
}
func (r *Field) _unmarshalJSONField(data []byte) (Field, error) {
result := Field{}
var partial map[string]json.RawMessage
err := json.Unmarshal(data, &partial)
if err != nil {
return result, fmt.Errorf("schema: Field._unmarshalJSONField: native struct unwrap; %w", err)
}
if fieldName, ok := partial["Name"]; ok {
result.Name, err = r._unmarshalJSONstring(fieldName)
if err != nil {
return result, fmt.Errorf("schema: Field._unmarshalJSONField: field Name; %w", err)
}
}
if fieldValue, ok := partial["Value"]; ok {
result.Value, err = r._unmarshalJSONSchema(fieldValue)
if err != nil {
return result, fmt.Errorf("schema: Field._unmarshalJSONField: field Value; %w", err)
}
}
return result, nil
}
func (r *Field) _unmarshalJSONstring(data []byte) (string, error) {
var result string
err := json.Unmarshal(data, &result)
if err != nil {
return result, fmt.Errorf("schema: Field._unmarshalJSONstring: native primitive unwrap; %w", err)
}
return result, nil
}
func (r *Field) _unmarshalJSONSchema(data []byte) (Schema, error) {
result, err := shared.JSONUnmarshal[Schema](data)
if err != nil {
return result, fmt.Errorf("schema: Field._unmarshalJSONSchema: native ref unwrap; %w", err)
}
return result, nil
}