pub fn ser_citation_location(
object_8: &mut ::aws_smithy_json::serialize::JsonObjectWriter,
input: &crate::types::CitationLocation,
) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::SerializationError> {
match input {
crate::types::CitationLocation::Web(inner) => {
#[allow(unused_mut)]
let mut object_1 = object_8.key("web").start_object();
crate::protocol_serde::shape_web_location::ser_web_location(&mut object_1, inner)?;
object_1.finish();
}
crate::types::CitationLocation::DocumentChar(inner) => {
#[allow(unused_mut)]
let mut object_2 = object_8.key("documentChar").start_object();
crate::protocol_serde::shape_document_char_location::ser_document_char_location(&mut object_2, inner)?;
object_2.finish();
}
crate::types::CitationLocation::DocumentPage(inner) => {
#[allow(unused_mut)]
let mut object_3 = object_8.key("documentPage").start_object();
crate::protocol_serde::shape_document_page_location::ser_document_page_location(&mut object_3, inner)?;
object_3.finish();
}
crate::types::CitationLocation::DocumentChunk(inner) => {
#[allow(unused_mut)]
let mut object_4 = object_8.key("documentChunk").start_object();
crate::protocol_serde::shape_document_chunk_location::ser_document_chunk_location(&mut object_4, inner)?;
object_4.finish();
}
crate::types::CitationLocation::SearchResultLocation(inner) => {
#[allow(unused_mut)]
let mut object_5 = object_8.key("searchResultLocation").start_object();
crate::protocol_serde::shape_search_result_location::ser_search_result_location(&mut object_5, inner)?;
object_5.finish();
}
crate::types::CitationLocation::Unknown => {
return Err(::aws_smithy_types::error::operation::SerializationError::unknown_variant(
"CitationLocation",
))
}
}
Ok(())
}
pub(crate) fn de_citation_location<'a, I>(
tokens: &mut ::std::iter::Peekable<I>,
_value: &'a [u8],
) -> ::std::result::Result<Option<crate::types::CitationLocation>, ::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() {
"web" => Some(crate::types::CitationLocation::Web(
crate::protocol_serde::shape_web_location::de_web_location(tokens, _value)?
.ok_or_else(|| ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'web' cannot be null"))?,
)),
"documentChar" => Some(crate::types::CitationLocation::DocumentChar(
crate::protocol_serde::shape_document_char_location::de_document_char_location(tokens, _value)?.ok_or_else(|| {
::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'documentChar' cannot be null")
})?,
)),
"documentPage" => Some(crate::types::CitationLocation::DocumentPage(
crate::protocol_serde::shape_document_page_location::de_document_page_location(tokens, _value)?.ok_or_else(|| {
::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'documentPage' cannot be null")
})?,
)),
"documentChunk" => Some(crate::types::CitationLocation::DocumentChunk(
crate::protocol_serde::shape_document_chunk_location::de_document_chunk_location(tokens, _value)?.ok_or_else(|| {
::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'documentChunk' cannot be null")
})?,
)),
"searchResultLocation" => Some(crate::types::CitationLocation::SearchResultLocation(
crate::protocol_serde::shape_search_result_location::de_search_result_location(tokens, _value)?.ok_or_else(|| {
::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'searchResultLocation' cannot be null")
})?,
)),
_ => {
::aws_smithy_json::deserialize::token::skip_value(tokens)?;
Some(crate::types::CitationLocation::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)
}