[英]JMS Serializer / Symfony class does not exist
I have an entity with some OneToOne relations:我有一个具有一些 OneToOne 关系的实体:
/**
* @OA\Property(type="integer")
* @Serializer\Groups({"list", "detail"})
* @Serializer\Type("File::class")
* @ORM\OneToOne(targetEntity="File")
*/
private ?File $cv = null;
And here is the File entity:这是文件实体:
/**
* @OA\Schema()
* @ORM\Entity(repositoryClass=FileRepository::class)
*/
class File
{
/**
* @OA\Property(type="integer")
* @Serializer\Groups({"list", "detail"})
* @Serializer\Type("integer")
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @OA\Property(type="string")
* @Serializer\Groups({"list", "detail"})
* @Serializer\Type("string")
* @ORM\Column(type="string", length=255, nullable=false)
*/
private $filename;
/**
* @OA\Property(type="string")
* @Serializer\Groups({"list", "detail"})
* @Serializer\Type("string")
* @ORM\Column(type="guid", nullable=false)
*/
private $uuid;
/**
* @OA\Property(type="string")
* @Serializer\Groups({"list", "detail"})
* @Serializer\Type("string")
* @ORM\Column(type="string", length=255, nullable=false)
*/
private $contentType;
/**
* @OA\Property(type="string", format="date-time")
* @Serializer\Groups({"list", "detail"})
* @Serializer\Type("string")
* @ORM\Column(type="date", length=255, nullable=false)
*/
private $creationDate;
When I try to serialize with JMS my first entity, with the OneToOne relation:当我尝试使用 JMS 序列化我的第一个实体时,使用 OneToOne 关系:
$data = $this->serializer->serialize($candidate, 'json', SerializationContext::create()->setGroups(array('detail'))->setSerializeNull(true));
I always got the error: Class File does not exist我总是收到错误:Class 文件不存在
Obviously, it's my @Type
annotation that is wrong, but why?显然,这是我的
@Type
注释错误,但为什么呢? What should I do.我应该怎么办。
Try changing this:尝试改变这个:
@Serializer\Type("File::class")
To this (no quotes):对此(无引号):
@Serializer\Type(File::class)
I suspect it may be looking for the literal string "File::class"
instead of parsing the class name.我怀疑它可能正在寻找文字字符串
"File::class"
,而不是解析 class 名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.