forked from prolicht-dev/avaclient-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel_i_element_dto_polymorphism.go
89 lines (77 loc) · 1.79 KB
/
model_i_element_dto_polymorphism.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
/*
* AVACloud API 1.16.0
*
* AVACloud API specification
*
* API version: 1.16.0
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
*/
package avaclient
import (
"encoding/json"
"fmt"
)
type IElementDtoHolder struct {
Holder IElementDto
}
func (t *IElementDtoHolder) MarshalJSON() ([]byte, error) {
return json.Marshal(t.Holder)
}
func (t *IElementDtoHolder) UnmarshalJSON(b []byte) error {
var objMap map[string]*json.RawMessage
err := json.Unmarshal(b, &objMap)
if err != nil {
return err
}
// We detect the correct struct type by looking at the elementTypeDiscriminator field.
jsonType, ok := objMap["elementTypeDiscriminator"]
if !ok {
return fmt.Errorf("no Type specification")
}
var goType string
err = json.Unmarshal(*jsonType, &goType)
if err != nil {
return fmt.Errorf("error getting type: %s", err.Error())
}
switch goType {
case "Position", "PositionDto":
var elem PositionDto
err = json.Unmarshal(b, &elem)
if err != nil {
return err
}
t.Holder = &elem
case "ExecutionDescription", "ExecutionDescriptionDto":
var elem ExecutionDescriptionDto
err = json.Unmarshal(b, &elem)
if err != nil {
return err
}
t.Holder = &elem
case "NoteText", "NoteTextDto":
var elem NoteTextDto
err = json.Unmarshal(b, &elem)
if err != nil {
return err
}
t.Holder = &elem
case "ServiceSpecificationGroup", "ServiceSpecificationGroupDto":
var elem ServiceSpecificationGroupDto
err = json.Unmarshal(b, &elem)
if err != nil {
return err
}
t.Holder = &elem
default:
return fmt.Errorf("unknown IElementDTO type %s", goType)
}
return nil
}
func (p PositionDto) isIElementDto() {
}
func (e ExecutionDescriptionDto) isIElementDto() {
}
func (n NoteTextDto) isIElementDto() {
}
func (s ServiceSpecificationGroupDto) isIElementDto() {
}