7 #include <packager/media/base/proto_json_util.h>
9 #include <absl/log/log.h>
10 #include <google/protobuf/util/json_util.h>
15 std::string MessageToJsonString(
const google::protobuf::Message& message) {
16 google::protobuf::util::JsonPrintOptions json_print_options;
17 json_print_options.preserve_proto_field_names =
true;
20 ABSL_CHECK_OK(google::protobuf::util::MessageToJsonString(
21 message, &result, json_print_options));
25 bool JsonStringToMessage(
const std::string& input,
26 google::protobuf::Message* message) {
27 google::protobuf::util::JsonParseOptions json_parse_options;
28 json_parse_options.ignore_unknown_fields =
true;
30 auto status = google::protobuf::util::JsonStringToMessage(input, message,
33 LOG(ERROR) <<
"Failed to parse from JSON: " << input
34 <<
" error: " << status.message();
All the methods that are virtual are virtual for mocking.