Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
None
-
None
-
None
Description
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, 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.
"int32_to_string": { "1": "value1", "1": "value2" }
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.
NOTE: The asV1Protobuf copy needs to also be updated.
Attachments
Issue Links
- relates to
-
MESOS-9896 Consider using protobuf provided json conversion facilities rather than custom ones.
- Accepted