x-x-p opened a new issue, #2995:
URL: https://github.com/apache/brpc/issues/2995
如下代码,使用json2pb将pb转为json,当遇到oneof时输出json与protobuf不一致
```c++
#include <json2pb/pb_to_json.h>
#include <google/protobuf/util/json_util.h>
#include "test.pb.h"
/*
* test.proto
*
syntax = "proto3";
message Test{
oneof OneOf{
string a = 1;
string b = 2;
string c = 3;
}
}
*/
int main()
{
Test test;
test.set_a("aaa");
{
std::string strJson;
json2pb::Pb2JsonOptions options;
options.always_print_primitive_fields = true;
json2pb::ProtoMessageToJson(test, &strJson, options);
std::cout << "json2pb: " << strJson << std::endl;
}
{
std::string strJson;
google::protobuf::util::JsonOptions options;
options.always_print_primitive_fields = true;
google::protobuf::util::MessageToJsonString(test, &strJson, options);
std::cout << "google: " << strJson << std::endl;
}
return 0;
}
```
以上代码中输出为:
```
json2pb: {"a":"aaa","b":"","c":""}
google: {"a":"aaa"}
```
brpc版本:1.12.1
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]