Uploaded image for project: 'Mesos'
  1. Mesos
  2. MESOS-8727

JSON -> protobuf conversion in stout handles duplicated keys in a map incorrectly

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • stout
    • None

    Description

      In Mesos code, we usually use the following two functions in stout to convert a JSON string to a protobuf message.

      1. JSON::parse() to convert a JSON string to a JSON object (i.e., JSON::Object).
      2. 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

          Activity

            People

              Unassigned Unassigned
              qianzhang Qian Zhang
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated: