From 499416c01101c162da133613d5c855912b17eb3e Mon Sep 17 00:00:00 2001 From: Chris Pick Date: Fri, 15 Feb 2019 15:20:34 -0500 Subject: [PATCH] fix(rust): teach remove_json_null_values arrays change `remove_json_null_values()` to properly remove nulls from and recurse in to arrays google_firestore1_beta1's `CommitRequest` contains an array of `Write` objects which can ultimately contain `Value` members that need to have nulls removed to avoid sending multiple types of values which generates a 400 response fixes calls to google_firestore1_beta1's `hub.projects().databases_documents_commit()` --- src/rust/api/cmn.rs | 11 +++++++++++ src/rust/cli/cmn.rs | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/rust/api/cmn.rs b/src/rust/api/cmn.rs index 906dbf900f..b157cda577 100644 --- a/src/rust/api/cmn.rs +++ b/src/rust/api/cmn.rs @@ -746,6 +746,17 @@ pub fn remove_json_null_values(value: &mut json::value::Value) { map.remove(key); } } + json::value::Value::Array(ref mut arr) => { + let mut i = 0; + while i < arr.len() { + if arr[i].is_null() { + arr.remove(i); + } else { + remove_json_null_values(&mut arr[i]); + i += 1; + } + } + } _ => {} } } diff --git a/src/rust/cli/cmn.rs b/src/rust/cli/cmn.rs index d1c46e6375..3f4407a5db 100644 --- a/src/rust/cli/cmn.rs +++ b/src/rust/cli/cmn.rs @@ -65,6 +65,17 @@ pub fn remove_json_null_values(value: &mut Value) { map.remove(key); } } + json::value::Value::Array(ref mut arr) => { + let mut i = 0; + while i < arr.len() { + if arr[i].is_null() { + arr.remove(i); + } else { + remove_json_null_values(&mut arr[i]); + i += 1; + } + } + } _ => {} } }