{"record":{"id":"0a9169f1fc0d6225","repo":"influxdata/influxdb","slug":"failed-to-serialize-the-request-body-0","errorCode":null,"errorMessage":"failed to serialize the request body: {0}","messagePattern":"failed to serialize the request body: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"influxdb3_client/src/lib.rs","lineNumber":34,"sourceCode":"use std::{fmt::Display, num::NonZeroUsize, path::PathBuf, string::FromUtf8Error, time::Duration};\nuse url::Url;\n\nuse influxdb3_types::http::*;\npub use influxdb3_types::write::Precision;\n\n/// Primary error type for the [`Client`]\n#[derive(Debug, thiserror::Error)]\npub enum Error {\n    #[error(\"base URL error: {}\", reqwest_description(.0))]\n    BaseUrl(#[source] reqwest::Error),\n\n    #[error(\"request URL error: {0}\")]\n    RequestUrl(#[from] url::ParseError),\n\n    #[error(\"failed to read the API response bytes: {}\", reqwest_description(.0))]\n    Bytes(#[source] reqwest::Error),\n\n    #[error(\"failed to serialize the request body: {0}\")]\n    RequestSerialization(#[source] serde_json::Error),\n\n    #[error(\n        \"provided parameter ('{name}') could not be converted \\\n        to a statment parameter\"\n    )]\n    ConvertQueryParam {\n        name: String,\n        #[source]\n        source: iox_query_params::Error,\n    },\n\n    #[error(\"invalid UTF8 in response: {0}\")]\n    InvalidUtf8(#[from] FromUtf8Error),\n\n    #[error(\"failed to parse JSON response: {}\", reqwest_description(.0))]\n    Json(#[source] reqwest::Error),\n","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/influxdata/influxdb/blob/06200ef96ba82c5f6727e5038a83af8e722c6875/influxdb3_client/src/lib.rs#L16-L52","documentation":"Error::RequestSerialization wraps a serde_json::Error raised while serializing the outgoing request body to JSON before sending. The client cannot produce a valid JSON payload from the value supplied by the caller.","triggerScenarios":"Calling write/metadata APIs with a body struct or value that serde_json cannot serialize (e.g. a map with non-string keys, NaN/f64 values in strict contexts, or a type that fails custom serialization).","commonSituations":"Hand-built line-protocol/JSON payloads with wrong field types after a struct change; dynamic serde_json::json! values containing unsupported types; version drift between client and payload types.","solutions":["Fix the payload type so it is JSON-serializable (string keys, JSON-compatible numeric types).","Serialize the body locally with serde_json::to_string first in debug flows to surface the exact serde error.","Update payload structs to match the client's expected API types after version upgrades."],"exampleFix":"// before\nlet body = std::collections::HashMap<i32, String>; // non-string keys\nclient.post(body).await?;\n// after\nlet body = std::collections::HashMap<String, String>;\nclient.post(body).await?;","handlingStrategy":"validation","validationCode":"// verify payload serializes before sending\nfn ensure_json<T: serde::Serialize>(v: &T) -> Result<(), serde_json::Error> {\n    serde_json::to_string(v).map(|_| ())\n}","typeGuard":null,"tryCatchPattern":"match serde_json::to_string(&body) {\n    Ok(s) => send(s).await,\n    Err(e) => Err(anyhow!(\"request body not serializable: {e}\")),\n}","preventionTips":["Use JSON-compatible field types (string map keys, no NaN).","Add round-trip serde tests for payload structs.","Keep payload types in sync across client/server version upgrades."],"tags":["serialization","json","serde","request-body"],"backgroundTag":"json-serialization-failed","analyzedSha":"06200ef96ba82c5f6727e5038a83af8e722c6875","analyzedAt":"2026-09-19T12:55:30.003Z","contentChangedAt":"2026-09-19T12:55:30.003Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}