{"record":{"id":"2425dff0f059df4c","repo":"nautechsystems/nautilus_trader","slug":"from-json-not-implemented-for","errorCode":null,"errorMessage":"from_json not implemented for {}","messagePattern":"from_json not implemented for (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/model/src/data/custom.rs","lineNumber":341,"sourceCode":"\n    /// Returns the type name used in serialized form (e.g. in the `\"type\"` field).\n    #[must_use]\n    fn type_name_static() -> &'static str\n    where\n        Self: Sized,\n    {\n        std::any::type_name::<Self>()\n    }\n\n    /// Deserializes from a JSON value into an Arc'd trait object.\n    ///\n    /// # Errors\n    /// Returns an error if JSON deserialization fails.\n    fn from_json(_value: serde_json::Value) -> anyhow::Result<Arc<dyn CustomDataTrait>>\n    where\n        Self: Sized,\n    {\n        anyhow::bail!(\n            \"from_json not implemented for {}\",\n            std::any::type_name::<Self>()\n        )\n    }\n}\n\n/// Registers a custom data type for JSON deserialization. When `Data::deserialize`\n/// sees the type name returned by `T::type_name_static()`, it will call `T::from_json`.\n///\n/// # Errors\n/// Returns an error if the type is already registered.\npub fn register_custom_data_json<T: CustomDataTrait + Sized>() -> anyhow::Result<()> {\n    let type_name = T::type_name_static();\n    register_json_deserializer(type_name, Box::new(|value| T::from_json(value)))\n}\n\n/// Registers a custom data type for JSON deserialization if not already registered.\n/// Idempotent: safe to call multiple times for the same type (e.g. module init).","sourceCodeStart":323,"sourceCodeEnd":359,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/data/custom.rs#L323-L359","documentation":"The CustomDataTrait::from_json default implementation is a stub that always fails. Types that do not override from_json cannot be deserialized from JSON, and the error names the concrete Rust type so the developer knows which registration/impl is missing.","triggerScenarios":"Calling from_json on a custom data type whose impl uses the default trait method instead of providing a real JSON deserializer.","commonSituations":"Adding a new custom data type and implementing serialization but forgetting the deserialization side; round-tripping custom data through JSON persistence where one direction was implemented.","solutions":["Implement from_json for the concrete type so it reconstructs the struct from the serde_json::Value.","If deserialization is genuinely unsupported, avoid JSON round-trips for this type and use the serialization-only path.","Check the type registry: register a JSON deserializer via register_json_deserializer so the framework routes to a working implementation."],"exampleFix":"// before\nfn from_json(_value: serde_json::Value) -> anyhow::Result<Arc<dyn CustomDataTrait>> {\n    // default stub, always bails\n}\n// after\nfn from_json(value: serde_json::Value) -> anyhow::Result<Arc<dyn CustomDataTrait>> {\n    let data: MyData = serde_json::from_value(value)?;\n    Ok(Arc::new(data))\n}","handlingStrategy":"try-catch","validationCode":"// Rust — fail fast at startup if the type lacks a real from_json\nfn supports_from_json<T: CustomDataTrait>() -> bool { std::any::type_name::<T>().len() > 0 } // pair with a round-trip test\n// Prefer: write a test that serializes and deserializes each custom type","typeGuard":null,"tryCatchPattern":"// Rust\nmatch MyData::from_json(value) {\n    Ok(data) => data,\n    Err(e) if e.to_string().starts_with(\"from_json not implemented\") => {\n        return Err(anyhow::anyhow!(\"custom type lacks JSON deserialization; add an impl\"))\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["When adding a custom data type, implement to_json and from_json together.","Add a serialize/deserialize round-trip unit test per custom type.","Register a JSON deserializer for every type exposed to persistence."],"tags":["rust","json","deserialization","custom-data"],"backgroundTag":"method-not-implemented","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}