invalid value "xxx" for type TYPE_ENUM
--Thanks,Qian
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+unsubscribe@googlegroups.com.
To post to this group, send email to prot...@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.
Note that you can use the always_print_enums_as_ints option to work around this problem:
https://github.com/google/protobuf/blob/master/src/google/protobuf/util/json_util.h#L73
With this option enum value will printed as integers and will be accepted by JsonStringToMessage.
This is the expected behavior. The issue at core is that protobuf message is only able to hold unknown binary data. It's designed that way with its UnknownFieldSet data structure and you can not achieve the same with other formats.
Note that you can use the always_print_enums_as_ints option to work around this problem:https://github.com/google/protobuf/blob/master/src/google/protobuf/util/json_util.h#L73With this option enum value will printed as integers and will be accepted by JsonStringToMessage.
"always_print_enums_as_ints" is an option for the method "MessageToJsonString()", but the issue that I am talking about is the method "JsonStringToMessage()", the only option that "JsonStringToMessage()" accepts is "JsonParseOptions.ignore_unknown_fields", but I do not think it can help here.This is the expected behavior. The issue at core is that protobuf message is only able to hold unknown binary data. It's designed that way with its UnknownFieldSet data structure and you can not achieve the same with other formats.But that behavior is not desired for us :-( We are implementing a server which can accept both protobuf serialized string and JSON string from clients, and then the server will call "ParseFromString()" and "JsonStringToMessage" to get the protobuf message from the serialized string and JSON string respectively. But now these two methods have different behaviors, "ParseFromString()" can successfully parse a serialized string which contains unrecognized enum value, but "JsonStringToMessage()" will fail to do that. This makes our server can not behave consistently for protobuf serialized string and JSON string.Any suggestions? Thanks!