Skip to main content

aws_sdk_glue/protocol_serde/
shape_union.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2pub fn ser_union(
3    object: &mut ::aws_smithy_json::serialize::JsonObjectWriter,
4    input: &crate::types::Union,
5) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::SerializationError> {
6    {
7        object.key("Name").string(input.name.as_str());
8    }
9    {
10        let mut array_1 = object.key("Inputs").start_array();
11        for item_2 in &input.inputs {
12            {
13                array_1.value().string(item_2.as_str());
14            }
15        }
16        array_1.finish();
17    }
18    {
19        object.key("UnionType").string(input.union_type.as_str());
20    }
21    Ok(())
22}
23
24pub(crate) fn de_union<'a, I>(
25    tokens: &mut ::std::iter::Peekable<I>,
26    _value: &'a [u8],
27) -> ::std::result::Result<Option<crate::types::Union>, ::aws_smithy_json::deserialize::error::DeserializeError>
28where
29    I: Iterator<Item = Result<::aws_smithy_json::deserialize::Token<'a>, ::aws_smithy_json::deserialize::error::DeserializeError>>,
30{
31    match tokens.next().transpose()? {
32        Some(::aws_smithy_json::deserialize::Token::ValueNull { .. }) => Ok(None),
33        Some(::aws_smithy_json::deserialize::Token::StartObject { .. }) => {
34            #[allow(unused_mut)]
35            let mut builder = crate::types::builders::UnionBuilder::default();
36            loop {
37                match tokens.next().transpose()? {
38                    Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
39                    Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => match key.to_unescaped()?.as_ref() {
40                        "Name" => {
41                            builder = builder.set_name(
42                                ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
43                                    .map(|s| s.to_unescaped().map(|u| u.into_owned()))
44                                    .transpose()?,
45                            );
46                        }
47                        "Inputs" => {
48                            builder = builder.set_inputs(crate::protocol_serde::shape_two_inputs::de_two_inputs(tokens, _value)?);
49                        }
50                        "UnionType" => {
51                            builder = builder.set_union_type(
52                                ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
53                                    .map(|s| s.to_unescaped().map(|u| crate::types::UnionType::from(u.as_ref())))
54                                    .transpose()?,
55                            );
56                        }
57                        _ => ::aws_smithy_json::deserialize::token::skip_value(tokens)?,
58                    },
59                    other => {
60                        return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
61                            "expected object key or end object, found: {other:?}"
62                        )))
63                    }
64                }
65            }
66            Ok(Some(crate::serde_util::union_correct_errors(builder).build().map_err(|err| {
67                ::aws_smithy_json::deserialize::error::DeserializeError::custom_source("Response was invalid", err)
68            })?))
69        }
70        _ => Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
71            "expected start object or null",
72        )),
73    }
74}