datadog_api_client/datadogV2/model/
model_case_update_attributes.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 CaseUpdateAttributes {
14 #[serde(rename = "attributes")]
16 pub attributes: crate::datadogV2::model::CaseUpdateAttributesAttributes,
17 #[serde(rename = "type")]
19 pub type_: crate::datadogV2::model::CaseResourceType,
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 CaseUpdateAttributes {
28 pub fn new(
29 attributes: crate::datadogV2::model::CaseUpdateAttributesAttributes,
30 type_: crate::datadogV2::model::CaseResourceType,
31 ) -> CaseUpdateAttributes {
32 CaseUpdateAttributes {
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 CaseUpdateAttributes {
50 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
51 where
52 D: Deserializer<'de>,
53 {
54 struct CaseUpdateAttributesVisitor;
55 impl<'a> Visitor<'a> for CaseUpdateAttributesVisitor {
56 type Value = CaseUpdateAttributes;
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<
67 crate::datadogV2::model::CaseUpdateAttributesAttributes,
68 > = None;
69 let mut type_: Option<crate::datadogV2::model::CaseResourceType> = None;
70 let mut additional_properties: std::collections::BTreeMap<
71 String,
72 serde_json::Value,
73 > = std::collections::BTreeMap::new();
74 let mut _unparsed = false;
75
76 while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
77 match k.as_str() {
78 "attributes" => {
79 attributes = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
80 }
81 "type" => {
82 type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
83 if let Some(ref _type_) = type_ {
84 match _type_ {
85 crate::datadogV2::model::CaseResourceType::UnparsedObject(
86 _type_,
87 ) => {
88 _unparsed = true;
89 }
90 _ => {}
91 }
92 }
93 }
94 &_ => {
95 if let Ok(value) = serde_json::from_value(v.clone()) {
96 additional_properties.insert(k, value);
97 }
98 }
99 }
100 }
101 let attributes = attributes.ok_or_else(|| M::Error::missing_field("attributes"))?;
102 let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?;
103
104 let content = CaseUpdateAttributes {
105 attributes,
106 type_,
107 additional_properties,
108 _unparsed,
109 };
110
111 Ok(content)
112 }
113 }
114
115 deserializer.deserialize_any(CaseUpdateAttributesVisitor)
116 }
117}