$record */ public function __construct(array $record) { $this->code = $record['code'] ?? null; $this->confidence = $record['confidence'] ?? null; } /** * @return array */ public function jsonSerialize(): array { $js = []; if ($this->code !== null) { $js['code'] = $this->code; } if ($this->confidence !== null) { $js['confidence'] = $this->confidence; } return $js; } }