Skip to main content

JsonCodecSettings

Struct JsonCodecSettings 

Source
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

Source

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.

Source

pub fn builder() -> JsonCodecSettingsBuilder

Creates a builder for JsonCodecSettings.

Source

pub fn default_timestamp_format(&self) -> TimestampFormat

Default timestamp format when not specified by @timestampFormat trait.

Source

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.

Source

pub fn strict_timestamp_formats(&self) -> bool

Whether timestamps must use exactly the wire form their format prescribes. See JsonCodecSettingsBuilder::strict_timestamp_formats.

Source

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.

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> JsonCodecSettings

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for JsonCodecSettings

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for JsonCodecSettings

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl DocumentSettings for JsonCodecSettings

Source§

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>

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>

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

The Smithy fully-qualified shape ID of the protocol that produced this document, e.g. "aws.protocols#restJson1". Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more