Skip to content

Commit

Permalink
AVRO-3949: [Rust]: Add support for serde to apache_avro::Decimal (#2772)
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
  • Loading branch information
martin-g authored Feb 27, 2024
1 parent 87f7fd2 commit 30cd024
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions lang/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lang/rust/avro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ crc32fast = { default-features = false, version = "1.4.0", optional = true }
digest = { default-features = false, version = "0.10.7", features = ["core-api"] }
libflate = { default-features = false, version = "2.0.0", features = ["std"] }
log = { workspace = true }
num-bigint = { default-features = false, version = "0.4.4" }
num-bigint = { default-features = false, version = "0.4.4", features = ["std", "serde"] }
regex-lite = { default-features = false, version = "0.1.5", features = ["std", "string"] }
serde = { workspace = true }
serde_json = { workspace = true }
Expand Down
13 changes: 12 additions & 1 deletion lang/rust/avro/src/decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use crate::{AvroResult, Error};
use num_bigint::{BigInt, Sign};

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Eq, serde::Serialize, serde::Deserialize)]
pub struct Decimal {
value: BigInt,
len: usize,
Expand Down Expand Up @@ -132,4 +132,15 @@ mod tests {

Ok(())
}

#[test]
fn avro_3949_decimal_serde() -> TestResult {
let decimal = Decimal::from(&[1, 2, 3]);

let ser = serde_json::to_string(&decimal)?;
let de = serde_json::from_str(&ser)?;
std::assert_eq!(decimal, de);

Ok(())
}
}

0 comments on commit 30cd024

Please sign in to comment.