我正在尝试为移动摘要序列化实体。我有这个实体类:
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Entity\User as BaseUser;
/**
* xxx\xxx\Entity\User
*
* @ORM\Table()
* @ORM\Entity()
* @ORM\Entity(repositoryClass="xxx\xxx\Entity\UserRepository")
*/
class User extends BaseUser
{
/**
*
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var \Doctrine\Common\Collections\ArrayCollection
*
* @ORM\OneToMany(targetEntity="\xxx\xxx\Entity\Music", mappedBy="user")
*/
protected $musics;
/**
* @var \Doctrine\Common\Collections\ArrayCollection
*
* @ORM\OneToMany(targetEntity="\xxx\xxx\Entity\Message", mappedBy="user")
*/
protected $messages;
/**
* @var \Doctrine\Common\Collections\ArrayCollection
*
* @ORM\OneToMany(targetEntity="\xxx\xxx\Entity\Location", mappedBy="user")
*/
protected $locations;
public function __construct()
{
parent::__construct();
$this->musics = new ArrayCollection();
$this->messages = new ArrayCollection();
$this->locations = new ArrayCollection();
}
}
现在,当我在我的DefaultController.php
:
$user = $this->getUser();
$em = $this->getDoctrine()->getManager();
$array = $em->getRepository('xxxBundle:User')
->findLatest();
$serializer = $this->get('serializer');
$response = $serializer->serialize($array, 'json'); //THIS LINE THROWS EXCEPTION
我有use Doctrine\Common\Collections\ArrayCollection;
,DefaultController.php
但似乎错误来自内部JMSSerializerBundle
。
到目前为止我尝试了什么
- 我尝试将
Doctrine
注释定义为以 a 开头\
,但这没有帮助 - 我已经清除了我的缓存一百万次
- 我搜索了类似的异常,但它们似乎都是由拼写错误引起的,我在过去 48 小时内检查了拼写错误,但找不到。
这些类是使用自动生成的app/console
。