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. On Tue, Oct 10, 2017 at 2:18 PM, Feng Xiao <[email protected]> wrote: > > > On Tue, Oct 10, 2017 at 12:29 AM, Qian Zhang <[email protected]> wrote: > >> Hi, >> >> I am using protobuf-3.3.0, and I found when parsing an unrecognized enum >> value for an optional enum field, the behaviors of "ParseFromString()" and >> "JsonStringToMessage()" are different. "ParseFromString()" will succeed and >> the field's getter method will return the default enum value, but >> "JsonStringToMessage" will fail with an error: >> >>> invalid value "xxx" for type TYPE_ENUM >>> >> >> Is this a bug of protobuf-3.3.0? IMHO, "ParseFromString()" and >> "JsonStringToMessage()" should have consistent behavior. >> > 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. > > >> >> >> 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 [email protected]. >> To post to this group, send email to [email protected]. >> Visit this group at https://groups.google.com/group/protobuf. >> For more options, visit https://groups.google.com/d/optout. >> > > -- 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/protobuf. For more options, visit https://groups.google.com/d/optout.
