Slide 26
Slide 26 text
json API の実装において Entity や Value Object に
を実装
26
整形処理の実装箇所
class User implements ¥JsonSerializable
{
// 略
public function jsonSerialize(): array
{
return [
'id' => $this->id,
'mail_address' => $this->mailAddress,
'profile' => [
'last_name' => $this->lastName,
'first_name' => $this->firstName,
'user_name' => $this->userName,
'sex' => $this->sex,
],
];
}
}
{
"id": 1,
"mail_address": "john@example.org",
"profile": {
"last_name": "Doe",
"first_name": "John",
"user_name": "johndoe",
"sex": "male"
}
}
jsonSerialize()