diff options
Diffstat (limited to 'src/google/protobuf/util/internal/json_objectwriter.cc')
-rw-r--r-- | src/google/protobuf/util/internal/json_objectwriter.cc | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/google/protobuf/util/internal/json_objectwriter.cc b/src/google/protobuf/util/internal/json_objectwriter.cc index b84210c1..6e4edd88 100644 --- a/src/google/protobuf/util/internal/json_objectwriter.cc +++ b/src/google/protobuf/util/internal/json_objectwriter.cc @@ -147,7 +147,7 @@ JsonObjectWriter* JsonObjectWriter::RenderBytes(StringPiece name, string base64; if (use_websafe_base64_for_bytes_) - WebSafeBase64Escape(value.ToString(), &base64); + WebSafeBase64EscapeWithPadding(value.ToString(), &base64); else Base64Escape(value, &base64); @@ -164,19 +164,32 @@ JsonObjectWriter* JsonObjectWriter::RenderNull(StringPiece name) { return RenderSimple(name, "null"); } +JsonObjectWriter* JsonObjectWriter::RenderNullAsEmpty(StringPiece name) { + return RenderSimple(name, ""); +} + void JsonObjectWriter::WritePrefix(StringPiece name) { bool not_first = !element()->is_first(); if (not_first) WriteChar(','); if (not_first || !element()->is_root()) NewLine(); - if (!name.empty()) { + bool empty_key_ok = GetAndResetEmptyKeyOk(); + if (!name.empty() || empty_key_ok) { WriteChar('"'); - ArrayByteSource source(name); - JsonEscaping::Escape(&source, &sink_); + if (!name.empty()) { + ArrayByteSource source(name); + JsonEscaping::Escape(&source, &sink_); + } stream_->WriteString("\":"); if (!indent_string_.empty()) WriteChar(' '); } } +bool JsonObjectWriter::GetAndResetEmptyKeyOk() { + bool retval = empty_name_ok_for_next_key_; + empty_name_ok_for_next_key_ = false; + return retval; +} + } // namespace converter } // namespace util } // namespace protobuf |