THRIFT-3126 PHP JSON serializer converts empty or int-indexed maps to lists

Client: php/test/Test/Thrift/JsonSerialize/JsonSerializeTest.php
Patch: Stig Bakken <stig@zedge.net>

This closes #479
This commit is contained in:
Jens Geyer 2015-05-05 21:10:50 +02:00
parent eec445ef8a
commit 89cffc6f76
2 changed files with 13 additions and 1 deletions

View File

@ -1092,7 +1092,11 @@ void t_php_generator::generate_php_struct_json_serialize(ofstream& out,
}
indent(out) << "if ($this->" << name << " !== null) {" << endl;
indent_up();
indent(out) << "$json->" << name << " = $this->" << name << ";" << endl;
indent(out) << "$json->" << name << " = ";
if (type->is_map()) {
out << "(object)";
}
out << "$this->" << name << ";" << endl;
indent_down();
indent(out) << "}" << endl;
}

View File

@ -92,4 +92,12 @@ class JsonSerializeTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($expected, json_decode(json_encode($nested)));
}
public function testMaps()
{
$intmap = new \ThriftTest\ThriftTest_testMap_args(['thing' => [0 => 'zero']]);
$emptymap = new \ThriftTest\ThriftTest_testMap_args([]);
$this->assertEquals('{"thing":{"0":"zero"}}', json_encode($intmap));
$this->assertEquals('{}', json_encode($emptymap));
}
}