aws_sdk_wafv2/protocol_serde/
shape_custom_response.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2pub fn ser_custom_response(
3    object: &mut ::aws_smithy_json::serialize::JsonObjectWriter,
4    input: &crate::types::CustomResponse,
5) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::SerializationError> {
6    {
7        object.key("ResponseCode").number(
8            #[allow(clippy::useless_conversion)]
9            ::aws_smithy_types::Number::NegInt((input.response_code).into()),
10        );
11    }
12    if let Some(var_1) = &input.custom_response_body_key {
13        object.key("CustomResponseBodyKey").string(var_1.as_str());
14    }
15    if let Some(var_2) = &input.response_headers {
16        let mut array_3 = object.key("ResponseHeaders").start_array();
17        for item_4 in var_2 {
18            {
19                #[allow(unused_mut)]
20                let mut object_5 = array_3.value().start_object();
21                crate::protocol_serde::shape_custom_http_header::ser_custom_http_header(&mut object_5, item_4)?;
22                object_5.finish();
23            }
24        }
25        array_3.finish();
26    }
27    Ok(())
28}
29
30pub(crate) fn de_custom_response<'a, I>(
31    tokens: &mut ::std::iter::Peekable<I>,
32) -> ::std::result::Result<Option<crate::types::CustomResponse>, ::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::CustomResponseBuilder::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                        "ResponseCode" => {
46                            builder = builder.set_response_code(
47                                ::aws_smithy_json::deserialize::token::expect_number_or_null(tokens.next())?
48                                    .map(i32::try_from)
49                                    .transpose()?,
50                            );
51                        }
52                        "CustomResponseBodyKey" => {
53                            builder = builder.set_custom_response_body_key(
54                                ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
55                                    .map(|s| s.to_unescaped().map(|u| u.into_owned()))
56                                    .transpose()?,
57                            );
58                        }
59                        "ResponseHeaders" => {
60                            builder = builder.set_response_headers(crate::protocol_serde::shape_custom_http_headers::de_custom_http_headers(tokens)?);
61                        }
62                        _ => ::aws_smithy_json::deserialize::token::skip_value(tokens)?,
63                    },
64                    other => {
65                        return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
66                            "expected object key or end object, found: {:?}",
67                            other
68                        )))
69                    }
70                }
71            }
72            Ok(Some(crate::serde_util::custom_response_correct_errors(builder).build().map_err(
73                |err| ::aws_smithy_json::deserialize::error::DeserializeError::custom_source("Response was invalid", err),
74            )?))
75        }
76        _ => Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
77            "expected start object or null",
78        )),
79    }
80}