Symfony JMSSerializerBundle RuntimeException:必须为实体定义类型::$field
我和JMSSerializerBundle有这个问题。这基本上给了我一个例外,因为我已经做了一些事情。这是我的实体: 编辑以避免注释线混淆 我已经检查过,Symfony JMSSerializerBundle RuntimeException:必须为实体定义类型::$field,symfony,doctrine,doctrine-orm,symfony-2.1,jmsserializerbundle,Symfony,Doctrine,Doctrine Orm,Symfony 2.1,Jmsserializerbundle,我和JMSSerializerBundle有这个问题。这基本上给了我一个例外,因为我已经做了一些事情。这是我的实体: 编辑以避免注释线混淆 我已经检查过,$content变量不是空的,并且所有字段都以JSON格式映射 在我的独白文件中,这正是一个例外: [2012-11-29 23:39:07] request.CRITICAL: JMS\SerializerBundle\Exception\RuntimeException: You must define a type for My\Pro
$content
变量不是空的,并且所有字段都以JSON格式映射
在我的独白文件中,这正是一个例外:
[2012-11-29 23:39:07] request.CRITICAL: JMS\SerializerBundle\Exception\RuntimeException:
You must define a type for My\ProjectBundle\Entity\Music::$album. (uncaught exception)
at /vendor/jms/serializer-bundle/JMS/SerializerBundle/Serializer/GenericDeserializationVisitor.php line 177
为什么它仍然给我这个例外?我很确定这是因为你有两个注释字符串,整个注释的不同部分。Symfony只查看类成员前面的注释字符串 尝试替换:
/** @Type("string")*/
/**
* @var string $album
*
* @ORM\Column(name="album", type="string")*/
protected $album;
与:
(在每个其他地方都有这些重复的注释注释)
这只是猜测,但我想它会解决的。当我尝试这样做时:
class Something
{
/**
* @var integer $id
*
* @ORM\Column(name="id", type="bigint", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
/**
*
*/
private $id;
}
…Symfony给了我这个错误:
No identifier/primary key specified for Entity 'SomeApp\SomeBundle\Entity\Something'. Every Entity must have an identifier/primary key.
我已经通过将整个项目更新为
devmaster
包解决了这个问题。这似乎是JMSSerializer中的一个bug,因为在不修改任何代码的情况下,我就不再得到这个错误
/**
* @var integer $duration
*
* @ORM\Column(name="duration", type="bigint")
* @Type("int")
*/
protected $duration;
不存在用于序列化的类型“int”,必须使用“integer”。这无关紧要。我只是尝试了不同的方法,但都不管用。我把它放在和条令相同的注释行中,您不需要将@Type与序列化程序已经从实体注释中获取的简单变量一起使用。该类型仅适用于包含相关对象的字段。。键入(“数组”)那么,为什么我会得到
异常
,我必须为$album
设置一个类型
,而它只是一个字符串?
class Something
{
/**
* @var integer $id
*
* @ORM\Column(name="id", type="bigint", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
/**
*
*/
private $id;
}
No identifier/primary key specified for Entity 'SomeApp\SomeBundle\Entity\Something'. Every Entity must have an identifier/primary key.
/**
* @var integer $duration
*
* @ORM\Column(name="duration", type="bigint")
* @Type("int")
*/
protected $duration;