datadog_api_client/datadogV2/model/
model_event_create_response.rs1use serde::de::{Error, MapAccess, Visitor};
5use serde::{Deserialize, Deserializer, Serialize};
6use serde_with::skip_serializing_none;
7use std::fmt::{self, Formatter};
8
9#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct EventCreateResponse {
14 #[serde(rename = "attributes")]
16 pub attributes: Option<crate::datadogV2::model::EventCreateResponseAttributes>,
17 #[serde(rename = "type")]
19 pub type_: Option<String>,
20 #[serde(flatten)]
21 pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
22 #[serde(skip)]
23 #[serde(default)]
24 pub(crate) _unparsed: bool,
25}
26
27impl EventCreateResponse {
28 pub fn new() -> EventCreateResponse {
29 EventCreateResponse {
30 attributes: None,
31 type_: None,
32 additional_properties: std::collections::BTreeMap::new(),
33 _unparsed: false,
34 }
35 }
36
37 pub fn attributes(
38 mut self,
39 value: crate::datadogV2::model::EventCreateResponseAttributes,
40 ) -> Self {
41 self.attributes = Some(value);
42 self
43 }
44
45 pub fn type_(mut self, value: String) -> Self {
46 self.type_ = Some(value);
47 self
48 }
49
50 pub fn additional_properties(
51 mut self,
52 value: std::collections::BTreeMap<String, serde_json::Value>,
53 ) -> Self {
54 self.additional_properties = value;
55 self
56 }
57}
58
59impl Default for EventCreateResponse {
60 fn default() -> Self {
61 Self::new()
62 }
63}
64
65impl<'de> Deserialize<'de> for EventCreateResponse {
66 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
67 where
68 D: Deserializer<'de>,
69 {
70 struct EventCreateResponseVisitor;
71 impl<'a> Visitor<'a> for EventCreateResponseVisitor {
72 type Value = EventCreateResponse;
73
74 fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
75 f.write_str("a mapping")
76 }
77
78 fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
79 where
80 M: MapAccess<'a>,
81 {
82 let mut attributes: Option<crate::datadogV2::model::EventCreateResponseAttributes> =
83 None;
84 let mut type_: Option<String> = None;
85 let mut additional_properties: std::collections::BTreeMap<
86 String,
87 serde_json::Value,
88 > = std::collections::BTreeMap::new();
89 let mut _unparsed = false;
90
91 while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
92 match k.as_str() {
93 "attributes" => {
94 if v.is_null() {
95 continue;
96 }
97 attributes = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
98 }
99 "type" => {
100 if v.is_null() {
101 continue;
102 }
103 type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
104 }
105 &_ => {
106 if let Ok(value) = serde_json::from_value(v.clone()) {
107 additional_properties.insert(k, value);
108 }
109 }
110 }
111 }
112
113 let content = EventCreateResponse {
114 attributes,
115 type_,
116 additional_properties,
117 _unparsed,
118 };
119
120 Ok(content)
121 }
122 }
123
124 deserializer.deserialize_any(EventCreateResponseVisitor)
125 }
126}