aws_sdk_securityhub/protocol_serde/
shape_aws_wafv2_custom_response_details.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2pub fn ser_aws_wafv2_custom_response_details(
3    object: &mut ::aws_smithy_json::serialize::JsonObjectWriter,
4    input: &crate::types::AwsWafv2CustomResponseDetails,
5) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::SerializationError> {
6    if let Some(var_1) = &input.custom_response_body_key {
7        object.key("CustomResponseBodyKey").string(var_1.as_str());
8    }
9    if let Some(var_2) = &input.response_code {
10        object.key("ResponseCode").number(
11            #[allow(clippy::useless_conversion)]
12            ::aws_smithy_types::Number::NegInt((*var_2).into()),
13        );
14    }
15    if let Some(var_3) = &input.response_headers {
16        let mut array_4 = object.key("ResponseHeaders").start_array();
17        for item_5 in var_3 {
18            {
19                #[allow(unused_mut)]
20                let mut object_6 = array_4.value().start_object();
21                crate::protocol_serde::shape_aws_wafv2_custom_http_header::ser_aws_wafv2_custom_http_header(&mut object_6, item_5)?;
22                object_6.finish();
23            }
24        }
25        array_4.finish();
26    }
27    Ok(())
28}
29
30pub(crate) fn de_aws_wafv2_custom_response_details<'a, I>(
31    tokens: &mut ::std::iter::Peekable<I>,
32) -> ::std::result::Result<Option<crate::types::AwsWafv2CustomResponseDetails>, ::aws_smithy_json::deserialize::error::DeserializeError>
33where
34    I: Iterator<Item = Result<::aws_smithy_json::deserialize::Token<'a>, ::aws_smithy_json::deserialize::error::DeserializeError>>,
35{
36    match tokens.next().transpose()? {
37        Some(::aws_smithy_json::deserialize::Token::ValueNull { .. }) => Ok(None),
38        Some(::aws_smithy_json::deserialize::Token::StartObject { .. }) => {
39            #[allow(unused_mut)]
40            let mut builder = crate::types::builders::AwsWafv2CustomResponseDetailsBuilder::default();
41            loop {
42                match tokens.next().transpose()? {
43                    Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
44                    Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => match key.to_unescaped()?.as_ref() {
45                        "CustomResponseBodyKey" => {
46                            builder = builder.set_custom_response_body_key(
47                                ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
48                                    .map(|s| s.to_unescaped().map(|u| u.into_owned()))
49                                    .transpose()?,
50                            );
51                        }
52                        "ResponseCode" => {
53                            builder = builder.set_response_code(
54                                ::aws_smithy_json::deserialize::token::expect_number_or_null(tokens.next())?
55                                    .map(i32::try_from)
56                                    .transpose()?,
57                            );
58                        }
59                        "ResponseHeaders" => {
60                            builder = builder.set_response_headers(
61                                crate::protocol_serde::shape_aws_wafv2_insert_headers_list::de_aws_wafv2_insert_headers_list(tokens)?,
62                            );
63                        }
64                        _ => ::aws_smithy_json::deserialize::token::skip_value(tokens)?,
65                    },
66                    other => {
67                        return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
68                            "expected object key or end object, found: {:?}",
69                            other
70                        )))
71                    }
72                }
73            }
74            Ok(Some(builder.build()))
75        }
76        _ => Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
77            "expected start object or null",
78        )),
79    }
80}