I am trying to serialize entities for mobile digest. I have this Entity class:
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();
}
}
Now when I call this line in my 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
I have use Doctrine\Common\Collections\ArrayCollection; in DefaultController.php, but it seems the error is coming from inside JMSSerializerBundle.
What have I tried thusfar
- I have tried defining the
Doctrineannotations to start with a\, but that didn’t help - I have cleared my cache a million times
- I have searched for similar exceptions, but they all seem to be caused by a typo and I’ve checked for typos for the last 48 hours and I can’t find one.
The classes were autogenerated with app/console.
Take a look at this issue on GitHub: https://github.com/schmittjoh/JMSSerializerBundle/issues/123