|
31 | 31 | #include "ortools/base/file.h" |
32 | 32 | #include "ortools/base/gzipstring.h" |
33 | 33 | #include "ortools/base/helpers.h" |
34 | | -#include "ortools/base/logging.h" |
35 | 34 | #include "ortools/base/options.h" |
36 | 35 | #include "ortools/base/status_macros.h" |
37 | 36 |
|
38 | 37 | namespace operations_research { |
39 | 38 |
|
40 | | -using google::protobuf::util::JsonParseOptions; |
41 | | -using google::protobuf::util::JsonStringToMessage; |
42 | | - |
43 | 39 | absl::StatusOr<std::string> ReadFileToString(absl::string_view filename) { |
44 | 40 | std::string contents; |
45 | 41 | RETURN_IF_ERROR(file::GetContents(filename, &contents, file::Defaults())); |
@@ -119,7 +115,7 @@ absl::Status StringToProto(absl::string_view data, |
119 | 115 | } |
120 | 116 | std::string json_error; |
121 | 117 | absl::Status json_status = |
122 | | - JsonStringToMessage(data, proto, JsonParseOptions()); |
| 118 | + ::google::protobuf::util::JsonStringToMessage(data, proto); |
123 | 119 | if (json_status.ok()) { |
124 | 120 | // NOTE(user): We protect against the JSON proto3 parser being very lenient |
125 | 121 | // and easily accepting any JSON as a valid JSON for our proto: if the |
@@ -164,34 +160,30 @@ absl::Status WriteProtoToFile(absl::string_view filename, |
164 | 160 | } |
165 | 161 | break; |
166 | 162 | case ProtoWriteFormat::kJson: { |
167 | | - google::protobuf::util::JsonPrintOptions options; |
| 163 | + google::protobuf::json::PrintOptions options; |
168 | 164 | options.add_whitespace = true; |
169 | | -#if PROTOBUF_VERSION >= 5026000 // Version 26.0.0 |
| 165 | + options.unquote_int64_if_possible = true; |
170 | 166 | options.always_print_fields_with_no_presence = true; |
171 | | -#else |
172 | | - options.always_print_primitive_fields = true; |
173 | | -#endif |
174 | 167 | options.preserve_proto_field_names = true; |
175 | | - if (!google::protobuf::util::MessageToJsonString(proto, &output_string, |
| 168 | + if (!google::protobuf::json::MessageToJsonString(proto, &output_string, |
176 | 169 | options) |
177 | 170 | .ok()) { |
178 | | - LOG(WARNING) << "Printing to stream failed."; |
179 | | - return make_error("google::protobuf::util::MessageToJsonString()"); |
| 171 | + return make_error("google::protobuf::json::MessageToJsonString()"); |
180 | 172 | } |
181 | 173 | file_type_suffix = ".json"; |
182 | 174 | break; |
183 | 175 | } |
184 | | - case ProtoWriteFormat::kCanonicalJson: |
| 176 | + case ProtoWriteFormat::kCanonicalJson: { |
185 | 177 | google::protobuf::util::JsonPrintOptions options; |
186 | 178 | options.add_whitespace = true; |
187 | 179 | if (!google::protobuf::util::MessageToJsonString(proto, &output_string, |
188 | 180 | options) |
189 | 181 | .ok()) { |
190 | | - LOG(WARNING) << "Printing to stream failed."; |
191 | 182 | return make_error("google::protobuf::util::MessageToJsonString()"); |
192 | 183 | } |
193 | 184 | file_type_suffix = ".json"; |
194 | 185 | break; |
| 186 | + } |
195 | 187 | } |
196 | 188 | if (gzipped) { |
197 | 189 | std::string gzip_string; |
|
0 commit comments