From dcd2c00fe6c08ff88c70903c06e2780db917db04 Mon Sep 17 00:00:00 2001 From: wing328 Date: Mon, 18 Jan 2016 21:42:24 +0800 Subject: [PATCH] fix empty object serialization issue --- .../src/main/resources/php/ObjectSerializer.mustache | 2 +- .../php/SwaggerClient-php/lib/ObjectSerializer.php | 2 +- .../php/SwaggerClient-php/tests/PetApiTest.php | 10 ++++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache b/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache index 263ade673a..414e40650f 100644 --- a/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache +++ b/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache @@ -71,7 +71,7 @@ class ObjectSerializer $values[$data::$attributeMap[$property]] = self::sanitizeForSerialization($data->$getter()); } } - $sanitized = $values; + $sanitized = (object)$values; } else { $sanitized = (string)$data; } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php b/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php index 9ee2f3c121..a4a1d06118 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php @@ -71,7 +71,7 @@ class ObjectSerializer $values[$data::$attributeMap[$property]] = self::sanitizeForSerialization($data->$getter()); } } - $sanitized = $values; + $sanitized = (object)$values; } else { $sanitized = (string)$data; } diff --git a/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php b/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php index dfc4597120..534b9d32c1 100644 --- a/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php @@ -316,6 +316,16 @@ class PetApiTest extends \PHPUnit_Framework_TestCase $this->assertSame($json['tags'][0]['id'], $pet_id); $this->assertSame($json['tags'][0]['name'], 'test php tag'); } + + // test empty object serialization + public function testEmptyPetSerialization() + { + $new_pet = new Swagger\Client\Model\Pet; + // the empty object should be serialised to {} + $this->assertSame("{}", "$new_pet"); + + } + } ?>