datadog_api_client/datadogV2/model/
model_event_payload_attributes.rs

1// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
2// This product includes software developed at Datadog (https://www.datadoghq.com/).
3// Copyright 2019-Present Datadog, Inc.
4use serde::{Deserialize, Deserializer, Serialize};
5
6/// JSON object for category-specific attributes. Schema is different per event category.
7#[non_exhaustive]
8#[derive(Clone, Debug, PartialEq, Serialize)]
9#[serde(untagged)]
10pub enum EventPayloadAttributes {
11    ChangeEventCustomAttributes(Box<crate::datadogV2::model::ChangeEventCustomAttributes>),
12    AlertEventCustomAttributes(Box<crate::datadogV2::model::AlertEventCustomAttributes>),
13    UnparsedObject(crate::datadog::UnparsedObject),
14}
15
16impl<'de> Deserialize<'de> for EventPayloadAttributes {
17    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
18    where
19        D: Deserializer<'de>,
20    {
21        let value: serde_json::Value = Deserialize::deserialize(deserializer)?;
22        if let Ok(_v) = serde_json::from_value::<
23            Box<crate::datadogV2::model::ChangeEventCustomAttributes>,
24        >(value.clone())
25        {
26            if !_v._unparsed {
27                return Ok(EventPayloadAttributes::ChangeEventCustomAttributes(_v));
28            }
29        }
30        if let Ok(_v) = serde_json::from_value::<
31            Box<crate::datadogV2::model::AlertEventCustomAttributes>,
32        >(value.clone())
33        {
34            if !_v._unparsed {
35                return Ok(EventPayloadAttributes::AlertEventCustomAttributes(_v));
36            }
37        }
38
39        return Ok(EventPayloadAttributes::UnparsedObject(
40            crate::datadog::UnparsedObject { value },
41        ));
42    }
43}