Skip to main content

decode_params

Function decode_params 

Source
pub fn decode_params<P: DeserializeOwned + Default>(
    value: Value,
) -> Result<P, Error>
Expand description

Decode a method’s params payload from the envelope’s serde_json::Value slot, treating Value::Null (the wire shape for an omitted params field, per SPEC §2.12.3) as equivalent to P::default().

Solves the “empty params struct can’t deserialize from null” hole: methods like system.ping SHOULD omit params (envelope.rs:55 doc), which arrives as Value::Null, but serde_json::from_value::<PingParams>(Null) would fail because PingParams expects an object. Routing every params decode through this helper lets the dispatcher accept both the canonical absent form and an explicit params: {} without per-method branching.

Wrong-shape non-null inputs (e.g. an array where an object is expected) still fail loudly through normal serde decoding — the helper only widens the null case.