Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix direct embedding of json values within decoded data for GraphSON::V3. #215

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions gremlin-client/src/io/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ macro_rules! g_serializer {
Ok(s.clone().into())
} else if let Value::Bool(b) = val {
Ok((*b).into())
} else if let Value::Null = val {
Ok(GValue::Null)
} else if let Value::Number(ref n) = val {
if let Some(i) = n.as_i64() {
Ok(i.into())
} else if let Some(f) = n.as_f64() {
Ok(f.into())
} else {
Err(GremlinError::Json("Expected number".to_string()))
}
} else if let Value::Array(ref l) = val {
Ok(l.iter().map($name).collect::<GremlinResult<Vec<GValue>>>()?.into())
} else {
let _type = &val["@type"];
let _type = get_value!(_type,serde_json::Value::String)?.as_str();
Expand Down
41 changes: 41 additions & 0 deletions gremlin-client/src/io/serializer_v3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ mod tests {

use super::deserializer_v3;
use serde_json::json;
use serde_json::Value;

use crate::{edge, vertex};

Expand Down Expand Up @@ -734,4 +735,44 @@ mod tests {

assert_eq!(result, GValue::Map(value_map));
}

#[test]
fn test_direct_decode() {
let value = json!({
"@type": "g:List",
"@value": [
json!(0.2),
json!(0.1),
]
});

let result = deserializer_v3(&value).expect("Failed to deserialize a List");

assert_eq!(
result,
GValue::List(vec![GValue::Double(0.2), GValue::Double(0.1)].into())
);

let value = json!({
"@type": "g:List",
"@value": [
Value::Null,
]
});

let result = deserializer_v3(&value).expect("Failed to deserialize a List");

assert_eq!(result, GValue::List(vec![GValue::Null].into()));

let value = json!({
"@type": "g:List",
"@value": [
json!(1),
]
});

let result = deserializer_v3(&value).expect("Failed to deserialize a List");

assert_eq!(result, GValue::List(vec![GValue::Int64(1)].into()));
}
}