Switch the get_loop_elements implementation to only return populated arrays when its an array-like object.

This commit is contained in:
Tom Alexander
2020-05-24 16:27:13 -04:00
parent 59ee4f508f
commit 966499db76
5 changed files with 14 additions and 50 deletions

View File

@@ -294,30 +294,8 @@ impl Walkable for serde_json::Value {
impl Loopable for serde_json::Value {
fn get_loop_elements(&self) -> Vec<&dyn ContextElement> {
match self {
serde_json::Value::Null => Vec::new(),
serde_json::Value::Bool(boolean) => {
if *boolean {
vec![self]
} else {
Vec::new()
}
}
serde_json::Value::Number(_num) => vec![self],
serde_json::Value::String(string_value) => {
if string_value.is_empty() {
Vec::new()
} else {
vec![self]
}
}
serde_json::Value::Array(array_value) => {
if array_value.is_empty() {
Vec::new()
} else {
array_value.iter().map(|x| x as _).collect()
}
}
serde_json::Value::Object(_obj) => vec![self],
serde_json::Value::Array(array_value) => array_value.iter().map(|x| x as _).collect(),
_ => Vec::new(),
}
}
}