datadog_api_client/datadogV2/model/
model_security_monitoring_signal.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 SecurityMonitoringSignal {
14 #[serde(rename = "attributes")]
17 pub attributes: Option<crate::datadogV2::model::SecurityMonitoringSignalAttributes>,
18 #[serde(rename = "id")]
20 pub id: Option<String>,
21 #[serde(rename = "type")]
23 pub type_: Option<crate::datadogV2::model::SecurityMonitoringSignalType>,
24 #[serde(flatten)]
25 pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
26 #[serde(skip)]
27 #[serde(default)]
28 pub(crate) _unparsed: bool,
29}
30
31impl SecurityMonitoringSignal {
32 pub fn new() -> SecurityMonitoringSignal {
33 SecurityMonitoringSignal {
34 attributes: None,
35 id: None,
36 type_: None,
37 additional_properties: std::collections::BTreeMap::new(),
38 _unparsed: false,
39 }
40 }
41
42 pub fn attributes(
43 mut self,
44 value: crate::datadogV2::model::SecurityMonitoringSignalAttributes,
45 ) -> Self {
46 self.attributes = Some(value);
47 self
48 }
49
50 pub fn id(mut self, value: String) -> Self {
51 self.id = Some(value);
52 self
53 }
54
55 pub fn type_(mut self, value: crate::datadogV2::model::SecurityMonitoringSignalType) -> Self {
56 self.type_ = Some(value);
57 self
58 }
59
60 pub fn additional_properties(
61 mut self,
62 value: std::collections::BTreeMap<String, serde_json::Value>,
63 ) -> Self {
64 self.additional_properties = value;
65 self
66 }
67}
68
69impl Default for SecurityMonitoringSignal {
70 fn default() -> Self {
71 Self::new()
72 }
73}
74
75impl<'de> Deserialize<'de> for SecurityMonitoringSignal {
76 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
77 where
78 D: Deserializer<'de>,
79 {
80 struct SecurityMonitoringSignalVisitor;
81 impl<'a> Visitor<'a> for SecurityMonitoringSignalVisitor {
82 type Value = SecurityMonitoringSignal;
83
84 fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
85 f.write_str("a mapping")
86 }
87
88 fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
89 where
90 M: MapAccess<'a>,
91 {
92 let mut attributes: Option<
93 crate::datadogV2::model::SecurityMonitoringSignalAttributes,
94 > = None;
95 let mut id: Option<String> = None;
96 let mut type_: Option<crate::datadogV2::model::SecurityMonitoringSignalType> = None;
97 let mut additional_properties: std::collections::BTreeMap<
98 String,
99 serde_json::Value,
100 > = std::collections::BTreeMap::new();
101 let mut _unparsed = false;
102
103 while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
104 match k.as_str() {
105 "attributes" => {
106 if v.is_null() {
107 continue;
108 }
109 attributes = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
110 }
111 "id" => {
112 if v.is_null() {
113 continue;
114 }
115 id = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
116 }
117 "type" => {
118 if v.is_null() {
119 continue;
120 }
121 type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
122 if let Some(ref _type_) = type_ {
123 match _type_ {
124 crate::datadogV2::model::SecurityMonitoringSignalType::UnparsedObject(_type_) => {
125 _unparsed = true;
126 },
127 _ => {}
128 }
129 }
130 }
131 &_ => {
132 if let Ok(value) = serde_json::from_value(v.clone()) {
133 additional_properties.insert(k, value);
134 }
135 }
136 }
137 }
138
139 let content = SecurityMonitoringSignal {
140 attributes,
141 id,
142 type_,
143 additional_properties,
144 _unparsed,
145 };
146
147 Ok(content)
148 }
149 }
150
151 deserializer.deserialize_any(SecurityMonitoringSignalVisitor)
152 }
153}