为JSON api使用本地Symfony序列器和验证器

83 阅读1分钟

如果你的API只针对JSON请求,那么你可以使用Symfony本地的serializer包,而不是更强大的JMS Serilizer包。使用方法见下面的例子。

安装

$ composer require symfony/serializer

配置

# services.yaml

请求工具(RequestUtil)

namespace App\Util;

ViolationUtil

declare(strict_types=1);

文本利用(TextUtil

declare(strict_types=1);

响应利用

namespace App\Util;

模型

用户

namespace App\Model\User\Update;

地址

namespace App\Model\User\Update;

占用者

namespace App\Model\User\Update;

使用情况

# Deserialize request as User model and validate it

请求

{