<?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
- 1 回答
- 0 關注
- 116 瀏覽
添加回答
舉報
0/150
提交
取消