[ 
https://issues.apache.org/jira/browse/THRIFT-2950?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15474752#comment-15474752
 ] 

zhaoyipeng commented on THRIFT-2950:
------------------------------------

This error is caused in generate_deserialize_set_element

indent(out) << "if (is_scalar($" << elem << ")) {" << endl;

should be

indent(out) << "if (!is_scalar($" << elem << ")) {" << endl;



> Thrift's PHP generated entity does not serialize SET type correctly 
> --------------------------------------------------------------------
>
>                 Key: THRIFT-2950
>                 URL: https://issues.apache.org/jira/browse/THRIFT-2950
>             Project: Thrift
>          Issue Type: Bug
>          Components: PHP - Compiler
>            Reporter: Dmitry Kiselev
>
> idl:
> {noformat}
> struct TTestEntity {
>     1:  string              id
>       2:  set<string>                 data
> }
> {noformat}
> php code generation works okay and we can set data
> {noformat}
> $entity = new TTestEntity();
> $entity->id = "hello";
> $entity->data = array("element1", "element2");
> $buffer = new TMemoryBuffer();
> $entity->write(new TJSONProtocol($buffer));
> echo $buffer->getBuffer();
> {noformat}
> but resulting JSON does not contain the set elements values:
> {noformat}
> {"1":{"str":"hello"},"2":{"set":["str",2,0,1]}}
> {noformat}
> If found the code generated by thrift that creates writes a string for SET:
> {code}
> foreach ($this->collection as $iter6 => $iter7)
> {
>     if (is_scalar($iter7)) {
>         $xfer += $output->writeString($iter6);
>     } else {
>         $xfer += $output->writeString($iter7);
>     }
> }
> {code}
> 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.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to