Qian Zhang created MESOS-8727:
---------------------------------

             Summary: JSON -> protobuf conversion in stout handles duplicated 
keys in a map incorrectly
                 Key: MESOS-8727
                 URL: https://issues.apache.org/jira/browse/MESOS-8727
             Project: Mesos
          Issue Type: Bug
          Components: stout
            Reporter: Qian Zhang


In Mesos code, we usually use the following two functions in stout to convert a 
JSON string to a protobuf message.
 # {{JSON::parse()}} to convert a JSON string to a JSON object (i.e., 
{{JSON::Object}}).
 # {{protobuf::parse()}} to convert the JSON object to a protobuf message.

In Google protobuf, there is a single function which can be used to achieve the 
same goal: {{JsonStringToMessage()}}. And based on [the doc of Google 
protobuf|https://developers.google.com/protocol-buffers/docs/proto#maps], if 
there are duplicated keys in a map in a JSON string, the conversion to protobuf 
message may fail, i.e., if we use {{JsonStringToMessage}} to convert the 
following JSON string to a protobuf message, it will fail with an error like 
{{int32_to_string[0]: Repeated map key: '1' is already set.}}

 
{code:java}
"int32_to_string": {
  "1": "value1",
  "1": "value2"
}
{code}
However, {{JSON::parse()}} and {{protobuf::parse()}} handles this case 
differently: they will succeed, and in the resulted protobuf message, we will 
see only one key-value pair {{"1": "value2"}}, i.e., the first key-value pair 
is overwritten. We should have the same behavior with {{JsonStringToMessage}}.

 

 



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to