fix empty object serialization issue

This commit is contained in:
wing328 2016-01-18 21:42:24 +08:00
parent 9fd4f39c8c
commit dcd2c00fe6
3 changed files with 12 additions and 2 deletions

View File

@ -71,7 +71,7 @@ class ObjectSerializer
$values[$data::$attributeMap[$property]] = self::sanitizeForSerialization($data->$getter());
}
}
$sanitized = $values;
$sanitized = (object)$values;
} else {
$sanitized = (string)$data;
}

View File

@ -71,7 +71,7 @@ class ObjectSerializer
$values[$data::$attributeMap[$property]] = self::sanitizeForSerialization($data->$getter());
}
}
$sanitized = $values;
$sanitized = (object)$values;
} else {
$sanitized = (string)$data;
}

View File

@ -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");
}
}
?>