datadog_api_client/datadogV2/model/
model_custom_framework_data.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 CustomFrameworkData {
14 #[serde(rename = "attributes")]
16 pub attributes: crate::datadogV2::model::CustomFrameworkDataAttributes,
17 #[serde(rename = "type")]
19 pub type_: crate::datadogV2::model::CustomFrameworkType,
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 CustomFrameworkData {
28 pub fn new(
29 attributes: crate::datadogV2::model::CustomFrameworkDataAttributes,
30 type_: crate::datadogV2::model::CustomFrameworkType,
31 ) -> CustomFrameworkData {
32 CustomFrameworkData {
33 attributes,
34 type_,
35 additional_properties: std::collections::BTreeMap::new(),
36 _unparsed: false,
37 }
38 }
39
40 pub fn additional_properties(
41 mut self,
42 value: std::collections::BTreeMap<String, serde_json::Value>,
43 ) -> Self {
44 self.additional_properties = value;
45 self
46 }
47}
48
49impl<'de> Deserialize<'de> for CustomFrameworkData {
50 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
51 where
52 D: Deserializer<'de>,
53 {
54 struct CustomFrameworkDataVisitor;
55 impl<'a> Visitor<'a> for CustomFrameworkDataVisitor {
56 type Value = CustomFrameworkData;
57
58 fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
59 f.write_str("a mapping")
60 }
61
62 fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
63 where
64 M: MapAccess<'a>,
65 {
66 let mut attributes: Option<crate::datadogV2::model::CustomFrameworkDataAttributes> =
67 None;
68 let mut type_: Option<crate::datadogV2::model::CustomFrameworkType> = None;
69 let mut additional_properties: std::collections::BTreeMap<
70 String,
71 serde_json::Value,
72 > = std::collections::BTreeMap::new();
73 let mut _unparsed = false;
74
75 while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
76 match k.as_str() {
77 "attributes" => {
78 attributes = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
79 }
80 "type" => {
81 type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
82 if let Some(ref _type_) = type_ {
83 match _type_ {
84 crate::datadogV2::model::CustomFrameworkType::UnparsedObject(_type_) => {
85 _unparsed = true;
86 },
87 _ => {}
88 }
89 }
90 }
91 &_ => {
92 if let Ok(value) = serde_json::from_value(v.clone()) {
93 additional_properties.insert(k, value);
94 }
95 }
96 }
97 }
98 let attributes = attributes.ok_or_else(|| M::Error::missing_field("attributes"))?;
99 let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?;
100
101 let content = CustomFrameworkData {
102 attributes,
103 type_,
104 additional_properties,
105 _unparsed,
106 };
107
108 Ok(content)
109 }
110 }
111
112 deserializer.deserialize_any(CustomFrameworkDataVisitor)
113 }
114}