aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorboscosiu <boscosiu@users.noreply.github.com>2019-05-31 16:01:05 -0700
committerAdam Cozzette <acozzette@google.com>2019-06-10 14:35:39 -0700
commit3cbe45a4b55952609dff0b3a9e2e7043679af93f (patch)
tree5a8c11f3c55f8c28a21b2cb4e59b7a650361c1f6 /src
parent6153f80876b61fcd6c48a4f0c89dc51ac144a4f6 (diff)
downloadprotobuf-3cbe45a4b55952609dff0b3a9e2e7043679af93f.tar.gz
JSON string output funtions should clear() the destination first
Make the JSON util string output functions match the Message::SerializeToString() behavior. This is helpful when packing the output into string fields of reused protobuf messages.
Diffstat (limited to 'src')
-rw-r--r--src/google/protobuf/util/json_util.cc2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/google/protobuf/util/json_util.cc b/src/google/protobuf/util/json_util.cc
index 52ce33100..c12c50cf5 100644
--- a/src/google/protobuf/util/json_util.cc
+++ b/src/google/protobuf/util/json_util.cc
@@ -115,6 +115,7 @@ util::Status BinaryToJsonString(TypeResolver* resolver,
const std::string& binary_input,
std::string* json_output,
const JsonPrintOptions& options) {
+ json_output->clear();
io::ArrayInputStream input_stream(binary_input.data(), binary_input.size());
io::StringOutputStream output_stream(json_output);
return BinaryToJsonStream(resolver, type_url, &input_stream, &output_stream,
@@ -209,6 +210,7 @@ util::Status JsonToBinaryString(TypeResolver* resolver,
StringPiece json_input,
std::string* binary_output,
const JsonParseOptions& options) {
+ binary_output->clear();
io::ArrayInputStream input_stream(json_input.data(), json_input.size());
io::StringOutputStream output_stream(binary_output);
return JsonToBinaryStream(resolver, type_url, &input_stream, &output_stream,