为了账号安全,请及时绑定邮箱和手机立即绑定

如何通过ApiPlatform保存json属性?

如何通过ApiPlatform保存json属性?

PHP
陪伴而非守候 2023-11-03 17:50:48
<?php/**  * @ApiResource( *     normalizationContext={"groups"={"fields_group:read"}}, *     denormalizationContext={"groups"={"fields_group:write"}} * ) */class Entity {    /**     * @var array Settings.     *     * @ORM\Column(type="json", options={"comment":"Settings"})     *     * @Assert\NotBlank()     * @Assert\Json()     *     * @Groups({"fields_group:read", "fields_group:write"})     * @ApiProperty(     *     attributes={     *         "openapi_context"={     *             "type"="object",     *             "example"={"option":"value"}     *         }     *     }     * )     */    private array $settings;    /**     * @return array     */    public function getSettings(): array    {        return $this->settings;    }    /**     * @param array $settings     *     * @return self     */    public function setSettings(array $settings): self    {        $this->settings = $settings;        return $this;    }}要求curl -X POST "https://localhost/api/entities" \    -H  "accept: application/ld+json" \    -H  "Content-Type: application/ld+json" \    -d "{\"settings\":{\"option\":\"value\"}}"回复{  "status": 400,  "message": "Expected argument of type \"string\", \"array\" given"}如何通过 ApiPlatform 保存 json 属性?
查看完整描述

1 回答

?
森林海

TA贡献2011条经验 获得超2个赞

Json验证器有罪https://github.com/symfony/validator/blob/v5.1.3/Constraints/JsonValidator.php#L37

这是多余的 ApiPlatform 将通过注释检查类型 @var array Settings


查看完整回答
反对 回复 2023-11-03
  • 1 回答
  • 0 关注
  • 54 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信