Repository: thrift
Updated Branches:
  refs/heads/master eec445ef8 -> 89cffc6f7


THRIFT-3126 PHP JSON serializer converts empty or int-indexed maps to lists
Client: php/test/Test/Thrift/JsonSerialize/JsonSerializeTest.php
Patch: Stig Bakken <[email protected]>

This closes #479


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/89cffc6f
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/89cffc6f
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/89cffc6f

Branch: refs/heads/master
Commit: 89cffc6f76389da2603aec3f7467c128f79055d2
Parents: eec445e
Author: Jens Geyer <[email protected]>
Authored: Tue May 5 21:10:50 2015 +0200
Committer: Jens Geyer <[email protected]>
Committed: Tue May 5 21:10:50 2015 +0200

----------------------------------------------------------------------
 compiler/cpp/src/generate/t_php_generator.cc                 | 6 +++++-
 lib/php/test/Test/Thrift/JsonSerialize/JsonSerializeTest.php | 8 ++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/89cffc6f/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 6c7da41..8919877 100644
--- a/compiler/cpp/src/generate/t_php_generator.cc
+++ b/compiler/cpp/src/generate/t_php_generator.cc
@@ -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;
     }

http://git-wip-us.apache.org/repos/asf/thrift/blob/89cffc6f/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 5c15bdf..40003ed 100644
--- a/lib/php/test/Test/Thrift/JsonSerialize/JsonSerializeTest.php
+++ b/lib/php/test/Test/Thrift/JsonSerialize/JsonSerializeTest.php
@@ -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));
+  }
+
 }

Reply via email to