pub fn ser_target(
object_2: &mut ::aws_smithy_json::serialize::JsonObjectWriter,
input: &crate::types::Target,
) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::SerializationError> {
match input {
crate::types::Target::AccountId(inner) => {
object_2.key("AccountId").string(inner.as_str());
}
crate::types::Target::OrganizationalUnitId(inner) => {
object_2.key("OrganizationalUnitId").string(inner.as_str());
}
crate::types::Target::RootId(inner) => {
object_2.key("RootId").string(inner.as_str());
}
crate::types::Target::Unknown => return Err(::aws_smithy_types::error::operation::SerializationError::unknown_variant("Target")),
}
Ok(())
}
pub(crate) fn de_target<'a, I>(
tokens: &mut ::std::iter::Peekable<I>,
_value: &'a [u8],
) -> ::std::result::Result<Option<crate::types::Target>, ::aws_smithy_json::deserialize::error::DeserializeError>
where
I: Iterator<Item = Result<::aws_smithy_json::deserialize::Token<'a>, ::aws_smithy_json::deserialize::error::DeserializeError>>,
{
let mut variant = None;
match tokens.next().transpose()? {
Some(::aws_smithy_json::deserialize::Token::ValueNull { .. }) => return Ok(None),
Some(::aws_smithy_json::deserialize::Token::StartObject { .. }) => loop {
match tokens.next().transpose()? {
Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => {
if let ::std::option::Option::Some(::std::result::Result::Ok(::aws_smithy_json::deserialize::Token::ValueNull { .. })) =
tokens.peek()
{
let _ = tokens.next().expect("peek returned a token")?;
continue;
}
let key = key.to_unescaped()?;
if key == "__type" {
::aws_smithy_json::deserialize::token::skip_value(tokens)?;
continue;
}
if variant.is_some() {
return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
"encountered mixed variants in union",
));
}
variant = match key.as_ref() {
"AccountId" => Some(crate::types::Target::AccountId(
::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
.map(|s| s.to_unescaped().map(|u| u.into_owned()))
.transpose()?
.ok_or_else(|| {
::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'AccountId' cannot be null")
})?,
)),
"OrganizationalUnitId" => Some(crate::types::Target::OrganizationalUnitId(
::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
.map(|s| s.to_unescaped().map(|u| u.into_owned()))
.transpose()?
.ok_or_else(|| {
::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'OrganizationalUnitId' cannot be null")
})?,
)),
"RootId" => Some(crate::types::Target::RootId(
::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
.map(|s| s.to_unescaped().map(|u| u.into_owned()))
.transpose()?
.ok_or_else(|| {
::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'RootId' cannot be null")
})?,
)),
_ => {
::aws_smithy_json::deserialize::token::skip_value(tokens)?;
Some(crate::types::Target::Unknown)
}
};
}
other => {
return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
"expected object key or end object, found: {other:?}"
)))
}
}
},
_ => {
return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
"expected start object or null",
))
}
}
if variant.is_none() {
return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
"Union did not contain a valid variant.",
));
}
Ok(variant)
}