Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-2950

Thrift's PHP generated entity does not serialize SET type correctly

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: PHP - Compiler
    • Labels:
      None

      Description

      idl:

      struct TTestEntity {
          1:  string              id
      	2:  set<string>			data
      }
      

      php code generation works okay and we can set data

      $entity = new TTestEntity();
      $entity->id = "hello";
      $entity->data = array("element1", "element2");
      
      $buffer = new TMemoryBuffer();
      $entity->write(new TJSONProtocol($buffer));
      echo $buffer->getBuffer();
      

      but resulting JSON does not contain the set elements values:

      {"1":{"str":"hello"},"2":{"set":["str",2,0,1]}}
      

      If found the code generated by thrift that creates writes a string for SET:

      foreach ($this->collection as $iter6 => $iter7)
      {
          if (is_scalar($iter7)) {
              $xfer += $output->writeString($iter6);
          } else {
              $xfer += $output->writeString($iter7);
          }
      }
      

      I can't explain why there is a check for is_scalar, but when array item value is string, number or boolean it writes array item key instead of value.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              dkiselew Dmitry Kiselev
            • Votes:
              2 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated: