pub struct DumpOptions {
pub mode: DumpMode,
pub include: Option<HashSet<String>>,
pub exclude: Option<HashSet<String>>,
pub by_alias: bool,
pub exclude_unset: bool,
pub exclude_defaults: bool,
pub exclude_none: bool,
pub exclude_computed_fields: bool,
pub round_trip: bool,
pub indent: Option<usize>,
}Expand description
Options for model_dump() and model_dump_json().
Controls the serialization behavior.
Fields§
§mode: DumpModeOutput mode: Json or Python (Rust native).
In Python/Pydantic, mode='json' produces JSON-compatible values while
mode='python' preserves native Python types (e.g., datetime objects).
In this crate, model_dump()/sql_model_dump() return serde_json::Value,
so both modes currently produce equivalent JSON-value output.
include: Option<HashSet<String>>Only include these fields (if Some)
exclude: Option<HashSet<String>>Exclude these fields
by_alias: boolUse field aliases in output.
When true, sql_model_dump() will rename fields to their
serialization_alias (or alias as fallback) in the output.
exclude_unset: boolExclude fields that were not explicitly set.
In Pydantic, this depends on tracking which fields were explicitly
provided at construction time (distinct from exclude_defaults).
Rust structs do not retain “field set” metadata by default, so this option is rejected at runtime to avoid silently producing incorrect output.
Pydantic semantics: If a field has a default value and the user explicitly
sets it to that default, it should still be included (it was “set”).
With exclude_defaults, it would be excluded regardless of whether
it was explicitly provided.
exclude_defaults: boolExclude fields with default values
exclude_none: boolExclude fields with None/null values
exclude_computed_fields: boolExclude computed fields (for future computed_field support)
round_trip: boolEnable round-trip mode (preserves types for re-parsing).
Pydantic can alter serialization to ensure a dump can be fed back into validation and reproduce the same model. This crate does not yet implement tagged round-trip encoding, so this flag is currently accepted as a no-op.
indent: Option<usize>Indentation for JSON output (None = compact, Some(n) = n spaces)
Implementations§
Source§impl DumpOptions
impl DumpOptions
Sourcepub fn include(
self,
fields: impl IntoIterator<Item = impl Into<String>>,
) -> Self
pub fn include( self, fields: impl IntoIterator<Item = impl Into<String>>, ) -> Self
Set fields to include.
Sourcepub fn exclude(
self,
fields: impl IntoIterator<Item = impl Into<String>>,
) -> Self
pub fn exclude( self, fields: impl IntoIterator<Item = impl Into<String>>, ) -> Self
Set fields to exclude.
Sourcepub fn exclude_unset(self) -> Self
pub fn exclude_unset(self) -> Self
Enable exclude_unset mode.
Sourcepub fn exclude_defaults(self) -> Self
pub fn exclude_defaults(self) -> Self
Enable exclude_defaults mode.
Sourcepub fn exclude_none(self) -> Self
pub fn exclude_none(self) -> Self
Enable exclude_none mode.
Sourcepub fn exclude_computed_fields(self) -> Self
pub fn exclude_computed_fields(self) -> Self
Enable exclude_computed_fields mode.
Sourcepub fn round_trip(self) -> Self
pub fn round_trip(self) -> Self
Enable round_trip mode.
Trait Implementations§
Source§impl Clone for DumpOptions
impl Clone for DumpOptions
Source§fn clone(&self) -> DumpOptions
fn clone(&self) -> DumpOptions
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more