Repository: thrift Updated Branches: refs/heads/master 867fafffa -> d6ca81b2c
PHP Compiler: always cast scalar types in jsonSerialize() Project: http://git-wip-us.apache.org/repos/asf/thrift/repo Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/d6ca81b2 Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/d6ca81b2 Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/d6ca81b2 Branch: refs/heads/master Commit: d6ca81b2cc7bed049a4f06242695f29549b49309 Parents: 867faff Author: Stig Bakken <[email protected]> Authored: Fri Jul 24 01:41:33 2015 +0200 Committer: Jens Geyer <[email protected]> Committed: Thu Oct 29 23:01:37 2015 +0200 ---------------------------------------------------------------------- compiler/cpp/src/generate/t_php_generator.cc | 2 ++ .../Test/Thrift/JsonSerialize/JsonSerializeTest.php | 13 +++++++++++++ 2 files changed, 15 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/thrift/blob/d6ca81b2/compiler/cpp/src/generate/t_php_generator.cc ---------------------------------------------------------------------- diff --git a/compiler/cpp/src/generate/t_php_generator.cc b/compiler/cpp/src/generate/t_php_generator.cc index c6d6f99..0c255ec 100644 --- a/compiler/cpp/src/generate/t_php_generator.cc +++ b/compiler/cpp/src/generate/t_php_generator.cc @@ -1097,6 +1097,8 @@ void t_php_generator::generate_php_struct_json_serialize(ofstream& out, indent(out) << "$json->" << name << " = "; if (type->is_map()) { out << "(object)"; + } else { + out << type_to_cast(type); } out << "$this->" << name << ";" << endl; indent_down(); http://git-wip-us.apache.org/repos/asf/thrift/blob/d6ca81b2/lib/php/test/Test/Thrift/JsonSerialize/JsonSerializeTest.php ---------------------------------------------------------------------- diff --git a/lib/php/test/Test/Thrift/JsonSerialize/JsonSerializeTest.php b/lib/php/test/Test/Thrift/JsonSerialize/JsonSerializeTest.php index 40003ed..2471b52 100644 --- a/lib/php/test/Test/Thrift/JsonSerialize/JsonSerializeTest.php +++ b/lib/php/test/Test/Thrift/JsonSerialize/JsonSerializeTest.php @@ -33,6 +33,11 @@ $loader->register(); class JsonSerializeTest extends \PHPUnit_Framework_TestCase { + protected function setUp() { + if (version_compare(phpversion(), '5.4', '<')) { + $this->markTestSkipped('Requires PHP 5.4 or newer!'); + } + } public function testEmptyStruct() { @@ -100,4 +105,12 @@ class JsonSerializeTest extends \PHPUnit_Framework_TestCase $this->assertEquals('{}', json_encode($emptymap)); } + public function testScalarTypes() + { + $b = new \ThriftTest\Bools(['im_true' => '1', 'im_false' => '0']); + $this->assertEquals('{"im_true":true,"im_false":false}', json_encode($b)); + $s = new \ThriftTest\StructA(['s' => 42]); + $this->assertEquals('{"s":"42"}', json_encode($s)); + } + }
