From 645ee0102ffeeff96f5845d400a8f4a2e6d98894 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sat, 6 Jul 2019 17:03:13 +0800 Subject: [PATCH] 1 --- cpp/utils.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cpp/utils.cc b/cpp/utils.cc index 592a48c..1ac7fa4 100644 --- a/cpp/utils.cc +++ b/cpp/utils.cc @@ -29,6 +29,9 @@ namespace f8 if (field_name.empty() || field_name[0] == '_') { continue; } + if (!reader.KeyExists(field_name) && field_desc->is_optional()) { + continue; + } switch (field_desc->cpp_type()) { case google::protobuf::FieldDescriptor::CPPTYPE_STRING: @@ -91,6 +94,9 @@ namespace f8 if (field_name.empty() || field_name[0] == '_') { continue; } + if (!jsonobj.HasKey(field_name) && field_desc->is_optional()) { + continue; + } if (field_desc->is_repeated()) { std::shared_ptr repeated_field = jsonobj.At(field_name);