pub struct JsonCodecSettings { /* private fields */ }Expand description
Configuration for JSON codec behavior.
Use the builder methods to construct settings:
use aws_smithy_json::codec::JsonCodecSettings;
let settings = JsonCodecSettings::builder()
.use_json_name(false)
.build();§As DocumentSettings
JsonCodecSettings implements [DocumentSettings]. The
JsonDeserializer attaches Arc<JsonCodecSettings> to every
document it produces so the format-aware accessors
(DiscriminatedDocument::as_blob,
DiscriminatedDocument::as_timestamp)
can coerce JSON-encoded blobs (base64 strings) and timestamps
(date-time strings or epoch-seconds numbers) back to typed Rust
values. The same instance is reused on the serialization side so a
document round-trips through JsonDeserializer →
JsonSerializer losslessly.
Implementations§
Source§impl JsonCodecSettings
impl JsonCodecSettings
Sourcepub fn dispatch_null_members(&self) -> bool
pub fn dispatch_null_members(&self) -> bool
Whether null structure members are passed to the consumer instead of skipped. Schema servers use this to clear optional fields while leaving required validation to builders.
Sourcepub fn builder() -> JsonCodecSettingsBuilder
pub fn builder() -> JsonCodecSettingsBuilder
Creates a builder for JsonCodecSettings.
Sourcepub fn default_timestamp_format(&self) -> TimestampFormat
pub fn default_timestamp_format(&self) -> TimestampFormat
Default timestamp format when not specified by @timestampFormat trait.
Sourcepub fn max_depth(&self) -> u32
pub fn max_depth(&self) -> u32
Maximum aggregate nesting depth the deserializer will accept before returning an error. Defends against stack overflow on recursive shapes and deeply-nested document payloads.
Sourcepub fn strict_timestamp_formats(&self) -> bool
pub fn strict_timestamp_formats(&self) -> bool
Whether timestamps must use exactly the wire form their format prescribes.
See JsonCodecSettingsBuilder::strict_timestamp_formats.
Sourcepub fn use_string_for_arbitrary_precision(&self) -> bool
pub fn use_string_for_arbitrary_precision(&self) -> bool
Whether bigInteger and bigDecimal shapes emit as JSON
strings (when true) or as raw JSON numbers
(when false, the default). The read path is always lenient —
read_big_integer and read_big_decimal accept either wire form.
Sourcepub fn normalize_arbitrary_precision(&self) -> bool
pub fn normalize_arbitrary_precision(&self) -> bool
Whether non-JSON-number arbitrary-precision text is rewritten to the equivalent JSON
number (true) or rejected (false, the default). See the field documentation.
Sourcepub fn default_namespace(&self) -> Option<&str>
pub fn default_namespace(&self) -> Option<&str>
Default Smithy namespace used to resolve relative shape IDs in
JSON __type discriminator fields. None if unset.
See the field-level doc comment for Self::default_namespace’s
builder method for the resolution behavior.
Sourcepub fn to_builder(&self) -> JsonCodecSettingsBuilder
pub fn to_builder(&self) -> JsonCodecSettingsBuilder
Returns a JsonCodecSettingsBuilder pre-populated with this
instance’s current values. Useful for protocol wrappers that
need to rebuild a codec with one setting overridden:
use aws_smithy_json::codec::JsonCodecSettings;
let original = JsonCodecSettings::default();
let modified = original.to_builder()
.default_namespace("com.example")
.build();Trait Implementations§
Source§impl Clone for JsonCodecSettings
impl Clone for JsonCodecSettings
Source§fn clone(&self) -> JsonCodecSettings
fn clone(&self) -> JsonCodecSettings
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for JsonCodecSettings
impl Debug for JsonCodecSettings
Source§impl Default for JsonCodecSettings
impl Default for JsonCodecSettings
Source§impl DocumentSettings for JsonCodecSettings
impl DocumentSettings for JsonCodecSettings
Source§fn coerce_string_to_blob(&self, s: &str) -> Result<Vec<u8>, DocumentError>
fn coerce_string_to_blob(&self, s: &str) -> Result<Vec<u8>, DocumentError>
Decodes a base64 string into a blob.
JSON has no native blob type; the
Smithy spec
requires blobs to be transmitted as base64-encoded strings on
the JSON wire. This method consumes those strings on the
deserialization side; the corresponding encode happens in
JsonSerializer::write_document.
Source§fn coerce_string_to_timestamp(&self, s: &str) -> Result<DateTime, DocumentError>
fn coerce_string_to_timestamp(&self, s: &str) -> Result<DateTime, DocumentError>
Parses a string-formatted timestamp using the codec’s default
timestamp format (JsonCodecSettings::default_timestamp_format).
Per the SEP, untyped JSON documents have no schema-level
@timestampFormat trait to consult, so the codec’s default
format is the only signal. AWS JSON / restJson1 default to
epoch-seconds — but a string-typed JSON value cannot be
epoch-seconds (which is a number). For this case we attempt
date-time parsing as a fallback so common ISO-8601 strings
still coerce.
Source§fn coerce_number_to_timestamp(
&self,
n: &Number,
) -> Result<DateTime, DocumentError>
fn coerce_number_to_timestamp( &self, n: &Number, ) -> Result<DateTime, DocumentError>
Coerces a number to a timestamp interpreted as
epoch-seconds.
Number-typed JSON values are only valid timestamps when the
codec’s default format is epoch-seconds. Per the SEP this is
the AWS JSON / restJson1 default. If the codec has been
configured with a non-numeric default format
(date-time / http-date), this method returns an
UnsupportedOperation error — a number value isn’t valid for
those formats.
Source§fn protocol_id(&self) -> &str
fn protocol_id(&self) -> &str
"aws.protocols#restJson1". Read moreAuto Trait Implementations§
impl Freeze for JsonCodecSettings
impl RefUnwindSafe for JsonCodecSettings
impl Send for JsonCodecSettings
impl Sync for JsonCodecSettings
impl Unpin for JsonCodecSettings
impl UnsafeUnpin for JsonCodecSettings
impl UnwindSafe for JsonCodecSettings
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§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