7
7
*
8
8
* http://www.apache.org/licenses/LICENSE-2.0
9
9
*
10
- * Unless Requiredd by applicable law or agreed to in writing, software
10
+ * Unless required by applicable law or agreed to in writing, software
11
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
* See the License for the specific language governing permissions and
@@ -393,6 +393,16 @@ const nlohmann::json& JsonReader::RequiredObject(const char* child_name,
393
393
return json_object.at (child_name);
394
394
}
395
395
396
+ const nlohmann::json& JsonReader::OptionalObject (
397
+ const char * child_name,
398
+ const json& json_object,
399
+ const nlohmann::json& default_value) {
400
+ if (json_object.contains (child_name)) {
401
+ return json_object.at (child_name);
402
+ }
403
+ return default_value;
404
+ }
405
+
396
406
double JsonReader::RequiredDouble (const char * name, const json& json_object) {
397
407
if (json_object.contains (name)) {
398
408
double result = DecodeDouble (json_object.at (name));
@@ -614,11 +624,22 @@ FilterList BundleSerializer::DecodeCompositeFilter(JsonReader& reader,
614
624
return {};
615
625
}
616
626
617
- auto filters = reader.RequiredArray (" filters" , filter);
627
+ const std::vector<json> default_filters;
628
+ const auto & filters =
629
+ reader.OptionalArray (" filters" , filter, default_filters);
630
+
631
+ const json default_objects;
618
632
FilterList result;
619
633
for (const auto & f : filters) {
620
- result = result.push_back (
621
- DecodeFieldFilter (reader, reader.RequiredObject (" fieldFilter" , f)));
634
+ const json& field_filter =
635
+ reader.OptionalObject (" fieldFilter" , f, default_objects);
636
+ if (!field_filter.empty ()) {
637
+ result = result.push_back (DecodeFieldFilter (reader, field_filter));
638
+ } else {
639
+ result = result.push_back (DecodeUnaryFilter (
640
+ reader, reader.OptionalObject (" unaryFilter" , f, default_objects)));
641
+ }
642
+
622
643
if (!reader.ok ()) {
623
644
return {};
624
645
}
@@ -636,8 +657,10 @@ Bound BundleSerializer::DecodeBound(JsonReader& reader,
636
657
return default_bound;
637
658
}
638
659
660
+ std::vector<json> default_values;
639
661
const json& bound_json = reader.RequiredObject (bound_name, query);
640
- std::vector<json> values = reader.RequiredArray (" values" , bound_json);
662
+ std::vector<json> values =
663
+ reader.OptionalArray (" values" , bound_json, default_values);
641
664
bool before = reader.OptionalBool (" before" , bound_json);
642
665
643
666
auto positions = MakeSharedMessage<google_firestore_v1_ArrayValue>({});
@@ -737,7 +760,9 @@ Message<google_firestore_v1_MapValue> BundleSerializer::DecodeMapValue(
737
760
738
761
Message<google_firestore_v1_ArrayValue> BundleSerializer::DecodeArrayValue (
739
762
JsonReader& reader, const json& array_json) const {
740
- const auto & values = reader.RequiredArray (" values" , array_json);
763
+ std::vector<json> default_values;
764
+ const auto & values =
765
+ reader.OptionalArray (" values" , array_json, default_values);
741
766
742
767
Message<google_firestore_v1_ArrayValue> array_value;
743
768
SetRepeatedField (
0 commit comments