【问题标题】:Symfony / api-platform PATCH NotEncodableValueException: "Syntax error"Symfony / api-platform PATCH NotEncodableValueException:“语法错误”
【发布时间】:2021-03-19 15:57:15
【问题描述】:

我使用 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;

【问题讨论】:

    标签: php api symfony api-platform.com


    【解决方案1】:

    我认为问题出在您的Content-Type 上,请检查一下。 应该是application/json如果是别的东西就改吧

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-23
      • 2020-02-16
      • 1970-01-01
      • 2021-07-13
      • 1970-01-01
      • 2021-02-20
      • 2014-04-05
      • 1970-01-01
      相关资源
      最近更新 更多