Skip to content

Commit

Permalink
Serialize i128 as JSON string
Browse files Browse the repository at this point in the history
  • Loading branch information
tustvold committed Jan 14, 2022
1 parent 68e5750 commit 2574d91
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion arrow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ path = "src/lib.rs"
[dependencies]
serde = { version = "1.0" }
serde_derive = "1.0"
serde_json = { version = "1.0", features = ["preserve_order", "arbitrary_precision"] }
serde_json = { version = "1.0", features = ["preserve_order"] }
indexmap = { version = "1.6", features = ["std"] }
rand = { version = "0.8", optional = true }
num = "0.4"
Expand Down
3 changes: 2 additions & 1 deletion arrow/src/datatypes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub type SchemaRef = Arc<Schema>;
mod tests {
use super::*;
use crate::error::Result;
use serde_json::Value::{Bool, Number as VNumber};
use serde_json::Value::{Bool, Number as VNumber, String as VString};
use serde_json::{Number, Value};
use std::{
collections::{BTreeMap, HashMap},
Expand Down Expand Up @@ -1180,6 +1180,7 @@ mod tests {
assert_eq!(Some(VNumber(Number::from(1))), 1u16.into_json_value());
assert_eq!(Some(VNumber(Number::from(1))), 1u32.into_json_value());
assert_eq!(Some(VNumber(Number::from(1))), 1u64.into_json_value());
assert_eq!(Some(VString("1".to_string())), 1i128.into_json_value());
assert_eq!(
Some(VNumber(Number::from_f64(0.01f64).unwrap())),
0.01.into_json_value()
Expand Down
6 changes: 5 additions & 1 deletion arrow/src/datatypes/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,11 @@ impl ArrowNativeType for i64 {

impl JsonSerializable for i128 {
fn into_json_value(self) -> Option<Value> {
Some(self.into())
// Serialize as string to avoid issues with arbitrary_precision serde_json feature
// - https://github.com/serde-rs/json/issues/559
// - https://github.com/serde-rs/json/issues/845
// - https://github.com/serde-rs/json/issues/846
Some(self.to_string().into())
}
}

Expand Down

0 comments on commit 2574d91

Please sign in to comment.