public function jsonSerialize()
{
$vars = get_object_vars($this);
foreach ($vars as $key => $value) {
if ($key === 'name' && !is_null($value)) {
continue;
} elseif (is_null($value) || $value === '') {
unset($vars[$key]);
}
}
if (empty($vars)) {
return;
}
return $vars;
}
/** * @see https://github.com/lesstif/php-jira-rest-client/issues/18 */ public function testEmptyAssignee() { $r = new Reporter(); $r->name = ''; $r->emailAddress = '*****@*****.**'; $r->avatarUrls = ''; $d = $r->jsonSerialize(); // passing a name value of '' then serialized array has 'name' key and empty value. $this->assertEquals(true, array_key_exists('name', $d), 'Can\'t found "name" key.'); $this->assertEquals(false, array_key_exists('avatarUrls', $d)); }