Symfony / api-平台 PATCH NotEncodableValueException:"Syntax error"
Symfony / api-platform PATCH NotEncodableValueException: "Syntax error"
我使用 api-平台,GET 和 POST 工作正常,我需要在我的实体中修补“isFinished”,但我有一个错误:
请求未捕获 PHP 异常 Symfony\Component\Serializer\Exception\NotEncodableValueException:“语法错误”
你认为我的实体配置有问题吗?
谢谢你的帮助。
/**
* @ApiResource()
* @ORM\Entity(repositoryClass=CurrentJourneyRepository::class)
*
* @ApiResource(
* collectionOperations={
* "get",
* "post"={"access_control"="is_granted('IS_AUTHENTICATED_ANONYMOUSLY')"},
* "patch"
* },
* itemOperations={
* "get",
* "patch",
* "put",
* "delete"={"security"="is_granted('ROLE_ADMIN')"}
* },
* normalizationContext={"groups"={"journey:read"}},
* denormalizationContext={"groups"={"journey:write"}},
*
*
* )
* @ApiFilter(SearchFilter::class, properties={"user","isFinished","treasureWay"})
*/
class CurrentJourney
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"journey:read"})
*/
private $id;
/**
* @ORM\Column(type="integer", nullable=true)
* @Groups({"journey:read", "journey:write"})
*/
private $try;
/**
* // * @ORM\ManyToOne(targetEntity=User::class, inversedBy="currentJourneys")
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="waypoints")
*/
private $user;
/**
* // * @ORM\ManyToOne(targetEntity=Waypoint::class, inversedBy="currentJourneys")
* @ORM\ManyToOne(targetEntity=Waypoint::class, inversedBy="users")
*/
private $waypoint;
/**
* @ORM\Column(type="integer",options={"default":"0"}) // integer: 0=abandonned ,1= in progress, 2= finished
* @Groups({"journey:read", "journey:write"})
*/
private $isFinished;
/**
* @ORM\Column(type="datetime")
*/
private $createdAt;
/**
* @ORM\ManyToOne(targetEntity=TreasureWay::class, inversedBy="currentJourneys")
*/
private $treasureWay;
我认为问题出在您的 Content-Type
上,检查一下。
应该是 application/json
如果是其他的就改一下
我使用 api-平台,GET 和 POST 工作正常,我需要在我的实体中修补“isFinished”,但我有一个错误: 请求未捕获 PHP 异常 Symfony\Component\Serializer\Exception\NotEncodableValueException:“语法错误”
你认为我的实体配置有问题吗? 谢谢你的帮助。
/**
* @ApiResource()
* @ORM\Entity(repositoryClass=CurrentJourneyRepository::class)
*
* @ApiResource(
* collectionOperations={
* "get",
* "post"={"access_control"="is_granted('IS_AUTHENTICATED_ANONYMOUSLY')"},
* "patch"
* },
* itemOperations={
* "get",
* "patch",
* "put",
* "delete"={"security"="is_granted('ROLE_ADMIN')"}
* },
* normalizationContext={"groups"={"journey:read"}},
* denormalizationContext={"groups"={"journey:write"}},
*
*
* )
* @ApiFilter(SearchFilter::class, properties={"user","isFinished","treasureWay"})
*/
class CurrentJourney
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"journey:read"})
*/
private $id;
/**
* @ORM\Column(type="integer", nullable=true)
* @Groups({"journey:read", "journey:write"})
*/
private $try;
/**
* // * @ORM\ManyToOne(targetEntity=User::class, inversedBy="currentJourneys")
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="waypoints")
*/
private $user;
/**
* // * @ORM\ManyToOne(targetEntity=Waypoint::class, inversedBy="currentJourneys")
* @ORM\ManyToOne(targetEntity=Waypoint::class, inversedBy="users")
*/
private $waypoint;
/**
* @ORM\Column(type="integer",options={"default":"0"}) // integer: 0=abandonned ,1= in progress, 2= finished
* @Groups({"journey:read", "journey:write"})
*/
private $isFinished;
/**
* @ORM\Column(type="datetime")
*/
private $createdAt;
/**
* @ORM\ManyToOne(targetEntity=TreasureWay::class, inversedBy="currentJourneys")
*/
private $treasureWay;
我认为问题出在您的 Content-Type
上,检查一下。
应该是 application/json
如果是其他的就改一下