--Thanks,Ron
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+u...@googlegroups.com.
To post to this group, send email to prot...@googlegroups.com.
Visit this group at http://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.
message Person
{
string first_name = 1;
string last_name = 2;
}
CgbXqNeV158={ "firstName": "" }Sure.For example, I defined the below message in the proto file:message Person
{
string first_name = 1;
string last_name = 2;
}
When I set the first_name field to "Ron" both binary serialization and JSON serialization work fine.But when I set it to "רון" (as UTF8) , while the serialization to binary is correct (shown here as base64):CgbXqNeV158=... when using BinaryToJsonString to get the JSON representation the value is mishandled and is ultimatately replaced with an empty string:{ "firstName": "" }This example will probably only work correctly with compilers that define char as unsigned by default, but with compilers that define char as signed (such as Microsoft's) - I think you should get the same (incorrect) result I pasted above.
Thanks for the explanation. Could you help file a bug for this on protobuf github site? If you know of an solution to this, you are also welcomed to send us a pull request.
...
#include <google/protobuf/message.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/util/json_util.h>
#include <google/protobuf/util/type_resolver_util.h>
using namespace google::protobuf;
using namespace google::protobuf::util;
...
void foo(const Message& msg)
{
...
std::string json_output;
TypeResolver* resolver = NewTypeResolverForDescriptorPool("type.googleapis.com", &DescriptorPool::generated_pool());
Status status = BinaryToJsonString(resolver, "type.googleapis.com/" + msg.GetTypeName(), msg.SerializeAsString(), &json_output);
std::cout << json_output;
delete resolver;
...
}
...