问题描述
我使用 api-platform,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
改变它