我有一个具有OneToOne关系的实体:
/**
* @OAProperty(type="integer")
* @SerializerGroups({"list", "detail"})
* @SerializerType("File::class")
* @ORMOneToOne(targetEntity="File")
*/
private ?File $cv = null;
这是文件实体:
/**
* @OASchema()
* @ORMEntity(repositoryClass=FileRepository::class)
*/
class File
{
/**
* @OAProperty(type="integer")
* @SerializerGroups({"list", "detail"})
* @SerializerType("integer")
* @ORMId
* @ORMGeneratedValue
* @ORMColumn(type="integer")
*/
private $id;
/**
* @OAProperty(type="string")
* @SerializerGroups({"list", "detail"})
* @SerializerType("string")
* @ORMColumn(type="string", length=255, nullable=false)
*/
private $filename;
/**
* @OAProperty(type="string")
* @SerializerGroups({"list", "detail"})
* @SerializerType("string")
* @ORMColumn(type="guid", nullable=false)
*/
private $uuid;
/**
* @OAProperty(type="string")
* @SerializerGroups({"list", "detail"})
* @SerializerType("string")
* @ORMColumn(type="string", length=255, nullable=false)
*/
private $contentType;
/**
* @OAProperty(type="string", format="date-time")
* @SerializerGroups({"list", "detail"})
* @SerializerType("string")
* @ORMColumn(type="date", length=255, nullable=false)
*/
private $creationDate;
当我尝试使用JMS序列化我的第一个实体时,使用OneToOne关系:
$data = $this->serializer->serialize($candidate, 'json', SerializationContext::create()->setGroups(array('detail'))->setSerializeNull(true));
我总是得到错误:类文件不存在
显然,我的@Type
注释是错误的,但为什么呢?我该怎么办?
尝试更改此项:@SerializerType("File::class")
对此(无引号(:@SerializerType(File::class)
我怀疑它可能在查找文字字符串"File::class"
,而不是解析类名。