pub struct JsonDeserializer<'a> { /* private fields */ }Expand description
JSON deserializer that implements the ShapeDeserializer trait.
Implementations§
Source§impl<'a> JsonDeserializer<'a>
impl<'a> JsonDeserializer<'a>
Source§impl<'a> JsonDeserializer<'a>
impl<'a> JsonDeserializer<'a>
Sourcepub fn read_discriminated_document(
&mut self,
) -> Result<DiscriminatedDocument, SerdeError>
pub fn read_discriminated_document( &mut self, ) -> Result<DiscriminatedDocument, SerdeError>
Reads a JSON document from the input, lifts an optional
top-level __type field into the result’s discriminator slot,
and attaches the codec’s [DocumentSettings] to the result so
downstream accessors like
DiscriminatedDocument::as_blob
and
DiscriminatedDocument::as_timestamp
can perform JSON-specific coercion (base64-decoded blobs,
format-aware timestamps).
§__type discriminator lift
When the parsed top-level value is a JSON object containing a
__type key whose value is an absolute Smithy shape ID
(namespace#ShapeName), the lift extracts that ID into the
resulting [DiscriminatedDocument]’s discriminator slot and
drops the key from the result map.
Falls back to leaving __type in the map when the value is
not a string, or is a relative shape name (no #) and no
default_namespace is configured. When a default_namespace
is set, a relative name is resolved against it before lifting.
§Example
use aws_smithy_json::codec::JsonCodec;
use aws_smithy_schema::codec::Codec;
let codec = JsonCodec::default();
let bytes = br#"{"__type":"smithy.example#Bird","name":"Iago"}"#;
let mut deser = codec.create_deserializer(bytes);
let doc = deser.read_discriminated_document().unwrap();
// `__type` was lifted into the discriminator slot.
assert_eq!(doc.discriminator(), Some("smithy.example#Bird"));
// The map no longer contains `__type`.
let map = doc.document().as_object().unwrap();
assert_eq!(map.len(), 1);
assert_eq!(map.get("name").and_then(|d| d.as_string()), Some("Iago"));Trait Implementations§
Source§impl<'a> ShapeDeserializer for JsonDeserializer<'a>
impl<'a> ShapeDeserializer for JsonDeserializer<'a>
Source§fn skip_value(&mut self) -> Result<(), SerdeError>
fn skip_value(&mut self) -> Result<(), SerdeError>
JSON shares one cursor across the whole object, so declining a value still has to move past it. Delegates to the same validating skip used for unknown members: a body copy of a transport-bound member is discarded, but it must still be well-formed JSON, so malformed content is reported rather than stepped over.
Source§fn read_struct(
&mut self,
schema: &Schema<'_>,
consumer: &mut dyn FnMut(&Schema<'_>, &mut dyn ShapeDeserializer) -> Result<(), SerdeError>,
) -> Result<(), SerdeError>
fn read_struct( &mut self, schema: &Schema<'_>, consumer: &mut dyn FnMut(&Schema<'_>, &mut dyn ShapeDeserializer) -> Result<(), SerdeError>, ) -> Result<(), SerdeError>
Source§fn read_list(
&mut self,
_schema: &Schema<'_>,
consumer: &mut dyn FnMut(&mut dyn ShapeDeserializer) -> Result<(), SerdeError>,
) -> Result<(), SerdeError>
fn read_list( &mut self, _schema: &Schema<'_>, consumer: &mut dyn FnMut(&mut dyn ShapeDeserializer) -> Result<(), SerdeError>, ) -> Result<(), SerdeError>
Source§fn read_map(
&mut self,
_schema: &Schema<'_>,
consumer: &mut dyn FnMut(String, &mut dyn ShapeDeserializer) -> Result<(), SerdeError>,
) -> Result<(), SerdeError>
fn read_map( &mut self, _schema: &Schema<'_>, consumer: &mut dyn FnMut(String, &mut dyn ShapeDeserializer) -> Result<(), SerdeError>, ) -> Result<(), SerdeError>
Source§fn read_boolean(&mut self, _schema: &Schema<'_>) -> Result<bool, SerdeError>
fn read_boolean(&mut self, _schema: &Schema<'_>) -> Result<bool, SerdeError>
Source§fn read_byte(&mut self, _schema: &Schema<'_>) -> Result<i8, SerdeError>
fn read_byte(&mut self, _schema: &Schema<'_>) -> Result<i8, SerdeError>
Source§fn read_short(&mut self, _schema: &Schema<'_>) -> Result<i16, SerdeError>
fn read_short(&mut self, _schema: &Schema<'_>) -> Result<i16, SerdeError>
Source§fn read_integer(&mut self, _schema: &Schema<'_>) -> Result<i32, SerdeError>
fn read_integer(&mut self, _schema: &Schema<'_>) -> Result<i32, SerdeError>
Source§fn read_long(&mut self, _schema: &Schema<'_>) -> Result<i64, SerdeError>
fn read_long(&mut self, _schema: &Schema<'_>) -> Result<i64, SerdeError>
Source§fn read_float(&mut self, _schema: &Schema<'_>) -> Result<f32, SerdeError>
fn read_float(&mut self, _schema: &Schema<'_>) -> Result<f32, SerdeError>
Source§fn read_double(&mut self, _schema: &Schema<'_>) -> Result<f64, SerdeError>
fn read_double(&mut self, _schema: &Schema<'_>) -> Result<f64, SerdeError>
Source§fn read_big_integer(
&mut self,
_schema: &Schema<'_>,
) -> Result<BigInteger, SerdeError>
fn read_big_integer( &mut self, _schema: &Schema<'_>, ) -> Result<BigInteger, SerdeError>
Source§fn read_big_decimal(
&mut self,
_schema: &Schema<'_>,
) -> Result<BigDecimal, SerdeError>
fn read_big_decimal( &mut self, _schema: &Schema<'_>, ) -> Result<BigDecimal, SerdeError>
Source§fn read_string(&mut self, _schema: &Schema<'_>) -> Result<String, SerdeError>
fn read_string(&mut self, _schema: &Schema<'_>) -> Result<String, SerdeError>
Source§fn read_blob(&mut self, _schema: &Schema<'_>) -> Result<Blob, SerdeError>
fn read_blob(&mut self, _schema: &Schema<'_>) -> Result<Blob, SerdeError>
Source§fn read_string_list(
&mut self,
_schema: &Schema<'_>,
) -> Result<Vec<String>, SerdeError>
fn read_string_list( &mut self, _schema: &Schema<'_>, ) -> Result<Vec<String>, SerdeError>
Source§fn read_blob_list(
&mut self,
_schema: &Schema<'_>,
) -> Result<Vec<Blob>, SerdeError>
fn read_blob_list( &mut self, _schema: &Schema<'_>, ) -> Result<Vec<Blob>, SerdeError>
Source§fn read_integer_list(
&mut self,
_schema: &Schema<'_>,
) -> Result<Vec<i32>, SerdeError>
fn read_integer_list( &mut self, _schema: &Schema<'_>, ) -> Result<Vec<i32>, SerdeError>
Source§fn read_long_list(
&mut self,
_schema: &Schema<'_>,
) -> Result<Vec<i64>, SerdeError>
fn read_long_list( &mut self, _schema: &Schema<'_>, ) -> Result<Vec<i64>, SerdeError>
Source§fn read_string_string_map(
&mut self,
_schema: &Schema<'_>,
) -> Result<HashMap<String, String>, SerdeError>
fn read_string_string_map( &mut self, _schema: &Schema<'_>, ) -> Result<HashMap<String, String>, SerdeError>
Source§fn read_timestamp(
&mut self,
schema: &Schema<'_>,
) -> Result<DateTime, SerdeError>
fn read_timestamp( &mut self, schema: &Schema<'_>, ) -> Result<DateTime, SerdeError>
Source§fn read_document(
&mut self,
_schema: &Schema<'_>,
) -> Result<Document, SerdeError>
fn read_document( &mut self, _schema: &Schema<'_>, ) -> Result<Document, SerdeError>
Auto Trait Implementations§
impl<'a> Freeze for JsonDeserializer<'a>
impl<'a> RefUnwindSafe for JsonDeserializer<'a>
impl<'a> Send for JsonDeserializer<'a>
impl<'a> Sync for JsonDeserializer<'a>
impl<'a> Unpin for JsonDeserializer<'a>
impl<'a> UnsafeUnpin for JsonDeserializer<'a>
impl<'a> UnwindSafe for JsonDeserializer<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more