Re: [protobuf] "ParseFromString()" and "JsonStringToMessage()" have inconsistent behavior when parsing an unrecognized enum value.

2017-10-17 Thread 'Feng Xiao' via Protocol Buffers
On Tue, Oct 10, 2017 at 8:15 PM, Qian Zhang  wrote:

> 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.
>
>
> "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!
>
There really isn't a good way to solve this. The server has to know the
enum definition to be able to accept it in JSON format. You will either
need to make sure the server is updated with the new definition before
sending it JSON data using the new enum names, or use integer instead of
enum names in the request.


>
>
> Regards,
> Qian Zhang
>
> On Wed, Oct 11, 2017 at 5:20 AM, Feng Xiao  wrote:
>
>> 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  wrote:
>>
>>>
>>>
>>> On Tue, Oct 10, 2017 at 12:29 AM, Qian Zhang 
>>> 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 protobuf+unsubscr...@googlegroups.com.
 To post to this group, send email to protobuf@googlegroups.com.
 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 protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.


[protobuf] Error in the Java Classes for Protocol Buffer 3.4.1

2017-10-17 Thread Nasim Hasan
Hello All,
I am Nasim Hasan and I am new to the Protocol Buffer. I will 
have to use the Protocol Buffer for communicating with a 3D Simulator 
(Gazebo). I am using the Protocol Buffer 3.4.1 for Java. But, when I use 
(by importing) the predefined classes for Java in my project, I am getting 
error from the following classes:

1. Descriptors.java.
2. DynamicMessage.java.
3. ExtensionRegistry.java.
4. MessageReflection.java.
5. TextFormat.java. 

So, can anyone from this group help me regarding this matter 
urgently... The help would be much appreciated..

Thanks-
Nasim Hasan

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.


Re: [protobuf] "ParseFromString()" and "JsonStringToMessage()" have inconsistent behavior when parsing an unrecognized enum value.

2017-10-17 Thread Qian Zhang
Feng, any comments? :-)

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.