Skip to content

Commit

Permalink
Serialize i128 as JSON string (#1175)
Browse files Browse the repository at this point in the history
  • Loading branch information
tustvold authored Jan 15, 2022
1 parent e6cb77b commit 1626b80
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 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
4 changes: 2 additions & 2 deletions 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 @@ -1175,7 +1175,7 @@ mod tests {
assert_eq!(Some(VNumber(Number::from(1))), 1i16.into_json_value());
assert_eq!(Some(VNumber(Number::from(1))), 1i32.into_json_value());
assert_eq!(Some(VNumber(Number::from(1))), 1i64.into_json_value());
assert_eq!(Some(VNumber(Number::from(1))), 1i128.into_json_value());
assert_eq!(Some(VString("1".to_string())), 1i128.into_json_value());
assert_eq!(Some(VNumber(Number::from(1))), 1u8.into_json_value());
assert_eq!(Some(VNumber(Number::from(1))), 1u16.into_json_value());
assert_eq!(Some(VNumber(Number::from(1))), 1u32.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 1626b80

Please sign in to comment.