mirror of
https://github.com/valitydev/thrift.git
synced 2024-11-07 10:48:51 +00:00
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:
parent
eec445ef8a
commit
89cffc6f76
@ -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;
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user