Skip to main content

ModelDump

Trait ModelDump 

Source
pub trait ModelDump {
    // Required method
    fn model_dump(&self, options: DumpOptions) -> DumpResult;

    // Provided methods
    fn model_dump_json(&self) -> Result<String, Error> { ... }
    fn model_dump_json_pretty(&self) -> Result<String, Error> { ... }
    fn model_dump_json_with_options(
        &self,
        options: DumpOptions,
    ) -> Result<String, Error> { ... }
}
Expand description

Trait for models that support model_dump().

This is typically implemented via blanket impl for models that implement Serialize.

Required Methods§

Source

fn model_dump(&self, options: DumpOptions) -> DumpResult

Serialize a model to a JSON value.

§Arguments
  • options - Dump options controlling serialization behavior
§Returns

A serde_json::Value representing the serialized model.

§Example
use sqlmodel_core::validate::{ModelDump, DumpOptions};

let json = user.model_dump(DumpOptions::default())?;

Provided Methods§

Source

fn model_dump_json(&self) -> Result<String, Error>

Serialize a model to a JSON string with default options.

Source

fn model_dump_json_pretty(&self) -> Result<String, Error>

Serialize a model to a pretty-printed JSON string.

Source

fn model_dump_json_with_options( &self, options: DumpOptions, ) -> Result<String, Error>

Serialize a model to a JSON string with full options support.

This method supports all DumpOptions including the indent option:

  • indent: None - compact JSON output
  • indent: Some(n) - pretty-printed with n spaces indentation
§Example
use sqlmodel_core::validate::{ModelDump, DumpOptions};

// Compact JSON with exclusions
let json = user.model_dump_json_with_options(
    DumpOptions::default().exclude(["password"])
)?;

// Pretty-printed with 4-space indent
let json = user.model_dump_json_with_options(
    DumpOptions::default().indent(4)
)?;

Implementors§

Source§

impl<T: Serialize> ModelDump for T

Blanket implementation of ModelDump for types that implement Serialize.