1 + | // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
|
2 + | pub(crate) fn de_my_union<'a, I>(
|
3 + | tokens: &mut ::std::iter::Peekable<I>,
|
4 + | ) -> ::std::result::Result<
|
5 + | Option<crate::unconstrained::my_union_unconstrained::MyUnionUnconstrained>,
|
6 + | ::aws_smithy_json::deserialize::error::DeserializeError,
|
7 + | >
|
8 + | where
|
9 + | I: Iterator<
|
10 + | Item = Result<
|
11 + | ::aws_smithy_json::deserialize::Token<'a>,
|
12 + | ::aws_smithy_json::deserialize::error::DeserializeError,
|
13 + | >,
|
14 + | >,
|
15 + | {
|
16 + | let mut variant = None;
|
17 + | match tokens.next().transpose()? {
|
18 + | Some(::aws_smithy_json::deserialize::Token::ValueNull { .. }) => return Ok(None),
|
19 + | Some(::aws_smithy_json::deserialize::Token::StartObject { .. }) => loop {
|
20 + | match tokens.next().transpose()? {
|
21 + | Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
|
22 + | Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => {
|
23 + | if let ::std::option::Option::Some(::std::result::Result::Ok(
|
24 + | ::aws_smithy_json::deserialize::Token::ValueNull { .. },
|
25 + | )) = tokens.peek()
|
26 + | {
|
27 + | let _ = tokens.next().expect("peek returned a token")?;
|
28 + | continue;
|
29 + | }
|
30 + | let key = key.to_unescaped()?;
|
31 + | if key == "__type" {
|
32 + | ::aws_smithy_json::deserialize::token::skip_value(tokens)?;
|
33 + | continue;
|
34 + | }
|
35 + | if variant.is_some() {
|
36 + | return Err(
|
37 + | ::aws_smithy_json::deserialize::error::DeserializeError::custom(
|
38 + | "encountered mixed variants in union",
|
39 + | ),
|
40 + | );
|
41 + | }
|
42 + | variant = match key.as_ref() {
|
43 + | "stringValue" => {
|
44 + | Some(crate::unconstrained::my_union_unconstrained::MyUnionUnconstrained::StringValue(
|
45 + | ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?.map(|s|
|
46 + | s.to_unescaped().map(|u|
|
47 + | u.into_owned()
|
48 + | )
|
49 + | ).transpose()?
|
50 + | .ok_or_else(|| ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'stringValue' cannot be null"))?
|
51 + | ))
|
52 + | }
|
53 + | "booleanValue" => {
|
54 + | Some(crate::unconstrained::my_union_unconstrained::MyUnionUnconstrained::BooleanValue(
|
55 + | ::aws_smithy_json::deserialize::token::expect_bool_or_null(tokens.next())?
|
56 + | .ok_or_else(|| ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'booleanValue' cannot be null"))?
|
57 + | ))
|
58 + | }
|
59 + | "numberValue" => {
|
60 + | Some(crate::unconstrained::my_union_unconstrained::MyUnionUnconstrained::NumberValue(
|
61 + | ::aws_smithy_json::deserialize::token::expect_number_or_null(tokens.next())?
|
62 + | .map(i32::try_from)
|
63 + | .transpose()?
|
64 + | .ok_or_else(|| ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'numberValue' cannot be null"))?
|
65 + | ))
|
66 + | }
|
67 + | "blobValue" => {
|
68 + | Some(crate::unconstrained::my_union_unconstrained::MyUnionUnconstrained::BlobValue(
|
69 + | ::aws_smithy_json::deserialize::token::expect_blob_or_null(tokens.next())?
|
70 + | .ok_or_else(|| ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'blobValue' cannot be null"))?
|
71 + | ))
|
72 + | }
|
73 + | "timestampValue" => {
|
74 + | Some(crate::unconstrained::my_union_unconstrained::MyUnionUnconstrained::TimestampValue(
|
75 + | ::aws_smithy_json::deserialize::token::expect_timestamp_or_null(tokens.next(), ::aws_smithy_types::date_time::Format::EpochSeconds)?
|
76 + | .ok_or_else(|| ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'timestampValue' cannot be null"))?
|
77 + | ))
|
78 + | }
|
79 + | "enumValue" => {
|
80 + | Some(crate::unconstrained::my_union_unconstrained::MyUnionUnconstrained::EnumValue(
|
81 + | ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?.map(|s|
|
82 + | s.to_unescaped().map(|u|
|
83 + | u.into_owned()
|
84 + | )
|
85 + | ).transpose()?
|
86 + | .ok_or_else(|| ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'enumValue' cannot be null"))?
|
87 + | ))
|
88 + | }
|
89 + | "listValue" => {
|
90 + | Some(crate::unconstrained::my_union_unconstrained::MyUnionUnconstrained::ListValue(
|
91 + | crate::protocol_serde::shape_string_list::de_string_list(tokens)?
|
92 + | .ok_or_else(|| ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'listValue' cannot be null"))?
|
93 + | ))
|
94 + | }
|
95 + | "mapValue" => {
|
96 + | Some(crate::unconstrained::my_union_unconstrained::MyUnionUnconstrained::MapValue(
|
97 + | crate::protocol_serde::shape_string_map::de_string_map(tokens)?
|
98 + | .ok_or_else(|| ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'mapValue' cannot be null"))?
|
99 + | ))
|
100 + | }
|
101 + | "structureValue" => {
|
102 + | Some(crate::unconstrained::my_union_unconstrained::MyUnionUnconstrained::StructureValue(
|
103 + | crate::protocol_serde::shape_greeting_struct::de_greeting_struct(tokens)?
|
104 + | .ok_or_else(|| ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'structureValue' cannot be null"))?
|
105 + | ))
|
106 + | }
|
107 + | variant => return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(format!("unexpected union variant: {variant}")))
|
108 + | };
|
109 + | }
|
110 + | other => {
|
111 + | return Err(
|
112 + | ::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
|
113 + | "expected object key or end object, found: {other:?}"
|
114 + | )),
|
115 + | )
|
116 + | }
|
117 + | }
|
118 + | },
|
119 + | _ => {
|
120 + | return Err(
|
121 + | ::aws_smithy_json::deserialize::error::DeserializeError::custom(
|
122 + | "expected start object or null",
|
123 + | ),
|
124 + | )
|
125 + | }
|
126 + | }
|
127 + | if variant.is_none() {
|
128 + | return Err(
|
129 + | ::aws_smithy_json::deserialize::error::DeserializeError::custom(
|
130 + | "Union did not contain a valid variant.",
|
131 + | ),
|
132 + | );
|
133 + | }
|
134 + | Ok(variant)
|
135 + | }
|
136 + |
|
137 + | pub fn ser_my_union(
|
138 + | object_2: &mut ::aws_smithy_json::serialize::JsonObjectWriter,
|
139 + | input: &crate::model::MyUnion,
|
140 + | ) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::SerializationError> {
|
141 + | match input {
|
142 + | crate::model::MyUnion::StringValue(inner) => {
|
143 + | object_2.key("stringValue").string(inner.as_str());
|
144 + | }
|
145 + | crate::model::MyUnion::BooleanValue(inner) => {
|
146 + | object_2.key("booleanValue").boolean(*inner);
|
147 + | }
|
148 + | crate::model::MyUnion::NumberValue(inner) => {
|
149 + | object_2.key("numberValue").number(
|
150 + | #[allow(clippy::useless_conversion)]
|
151 + | ::aws_smithy_types::Number::NegInt((*inner).into()),
|
152 + | );
|
153 + | }
|
154 + | crate::model::MyUnion::BlobValue(inner) => {
|
155 + | object_2
|
156 + | .key("blobValue")
|
157 + | .string_unchecked(&::aws_smithy_types::base64::encode(inner));
|
158 + | }
|
159 + | crate::model::MyUnion::TimestampValue(inner) => {
|
160 + | object_2
|
161 + | .key("timestampValue")
|
162 + | .date_time(inner, ::aws_smithy_types::date_time::Format::EpochSeconds)?;
|
163 + | }
|
164 + | crate::model::MyUnion::EnumValue(inner) => {
|
165 + | object_2.key("enumValue").string(inner.as_str());
|
166 + | }
|
167 + | crate::model::MyUnion::ListValue(inner) => {
|
168 + | let mut array_1 = object_2.key("listValue").start_array();
|
169 + | for item_2 in inner {
|
170 + | {
|
171 + | array_1.value().string(item_2.as_str());
|
172 + | }
|
173 + | }
|
174 + | array_1.finish();
|
175 + | }
|
176 + | crate::model::MyUnion::MapValue(inner) => {
|
177 + | #[allow(unused_mut)]
|
178 + | let mut object_3 = object_2.key("mapValue").start_object();
|
179 + | for (key_4, value_5) in inner {
|
180 + | {
|
181 + | object_3.key(key_4.as_str()).string(value_5.as_str());
|
182 + | }
|
183 + | }
|
184 + | object_3.finish();
|
185 + | }
|
186 + | crate::model::MyUnion::StructureValue(inner) => {
|
187 + | #[allow(unused_mut)]
|
188 + | let mut object_6 = object_2.key("structureValue").start_object();
|
189 + | crate::protocol_serde::shape_greeting_struct::ser_greeting_struct(
|
190 + | &mut object_6,
|
191 + | inner,
|
192 + | )?;
|
193 + | object_6.finish();
|
194 + | }
|
195 + | }
|
196 + | Ok(())
|
197 + | }
|