sqlx::types:BigDecimal and json serialization


I'm really new to rust and the language seems challenging. I'm using sqlx to query table into struct.

#[derive(Debug, sqlx::FromRow, serde::Serialize, serde::Deserialize)]
pub struct Position {
pub id: i32,
pub symbol: String,
pub qty: sqlx::types::BigDecimal

however the compile throws error regarding serializing BigDecimal.

the trait configuration::_::_serde::Serialize is not implemented for BigDecimal

I cannot find any information about serializing sqlx::types::BigDecimal on google, so I hope this community can help.

The BigDecimal type is a re-export from version 0.2.x of the bigdecimal crate, which has an optional serde feature. You can enable it like this:

bigdecimal = { version = "0.2", features = ["serde"] }

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.