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

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

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • PHP - Compiler
    • 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

            Unassigned Unassigned
            dkiselew Dmitry Kiselev
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: