Commit a62f7946 authored by wangyao02's avatar wangyao02

- fix compile error

parent cf685def
......@@ -20,10 +20,11 @@ Pb2JsonOptions::Pb2JsonOptions()
, pretty_json(false)
, enable_protobuf_map(true)
#ifdef BAIDU_INTERNAL
, bytes_to_base64(false) {
, bytes_to_base64(false)
#else
, bytes_to_base64(true) {
, bytes_to_base64(true)
#endif
, jsonify_empty_array(false) {
}
class PbToJsonConverter {
......@@ -89,7 +90,8 @@ bool PbToJsonConverter::Convert(const google::protobuf::Message& message, Handle
}
continue;
} else if (field->is_repeated()
&& reflection->FieldSize(message, field) == 0) {
&& reflection->FieldSize(message, field) == 0
&& !_option.jsonify_empty_array) {
// Repeated field that has no entry
continue;
}
......
......@@ -38,6 +38,11 @@ struct Pb2JsonOptions {
// encoding when this option is turned on.
// Default: false for baidu-internal, true otherwise.
bool bytes_to_base64;
// Convert the repeated field that has no entry
// to a empty array of json when this option is turned on.
// Default: false
bool jsonify_empty_array;
};
// Convert protobuf `messge' to `json' according to `options'.
......
......@@ -13,6 +13,9 @@ bool IsProtobufMap(const FieldDescriptor* field) {
return false;
}
const Descriptor* entry_desc = field->message_type();
if (entry_desc == NULL) {
return false;
}
if (entry_desc->field_count() != 2) {
return false;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment