JMSSerializerBundle: Anotation "@Enum" was never imported error

Hi guys,

I’m having an error trying to serialize an Doctrine Entity. I get the following error:

[Semantical Error] The annotation “@Enum” in property Doctrine\ORM\Mapping\ManyToMany::$fetch was never imported. Did you maybe forget to add a “use” statement for this annotation?

The entity has excluded all the properties explicitly, and some are exposed with the @Expose method. Here is the code:

<?php

namespace Aaa\Bundle\CoreBundle\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;

use FOS\UserBundle\Model\User as BaseUser;
use Sylius\Bundle\AddressingBundle\Model\AddressInterface;
use JMS\Serializer\Annotation\ExclusionPolicy;
use JMS\Serializer\Annotation\Expose;


/**
 *
 * @ORM\Entity
 * @ORM\Table(name="aaa_as_user")
 * @ExclusionPolicy("all")
 *
 */
class AsUser extends BaseUser
{
    /**
     * @var integer $id
     * @ORM\Column(type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     * @Expose
     */
    protected $id;

    /**
     * @var integer $aaaId
     * @ORM\Column(type="string", length=13, nullable=true)
     */
    protected $aaaId;

    /**
     * @var string $firstName
     * @ORM\Column(type="string", length=255)
     * @Expose
     */
    protected $firstName;

    /**
     * @var string $lastName
     * @ORM\Column(type="string", length=255)
     */
    protected $lastName;

    /**
     * @var DateTime $createdAt
     * @ORM\Column(name="created_at", type="datetime")
     * @Gedmo\Timestampable(on="create")
     * @Expose
     */
    protected $createdAt;
...
}

So, I don’t have any ideas what could be wrong. It seems that the doctrine anotations are not being loaded correctly in the anotations I use here.

I’ve read a similar issue here but it’s not a proxy issue so I have no idea how to solve this (as the property that has the ManyToOne is excluded, as you can see in the code above; only the present properties are exposed).

So… is this a bug? Or I’m missing some config? Any ideas?

Thanks a lot for your help!

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 26 (4 by maintainers)

Most upvoted comments

I had the same error, the problem was my fault, because after using createQueryBuilder(), I forgot to add ->getQuery()->getResult(). A sane error message would be nice, though.

@solazs never mind. Solved :'p

I was trying to parse an Paginator instance with JMSSearializer (I’m using FOS Rest).

//...on the repo
        $query->orderBy('o.created', 'ASC')
                ->setMaxResults($maxResults)
                ->setFirstResult($firstResult);
        $paginator = new Paginator($query, true);
        try {
            return $paginator;
        } catch (\Doctrine\ORM\NoResultException $e) {
            return null;
        }


//...on the fos rest controller
        //Paginator object returned
        $paginatorResult = $em->getRepository('BicEntityBundle:Whatever')->findSearched($what, $firstResult, $nResults);

        return $this->handleView(
                $this->view(
                        //because Paginator class implements IteratorAggregate
                        $paginatorResult->getIterator()->getArrayCopy(), 200
                        )
                //just to create the pagination
                ->setHeader('n_results', count($paginatorResult)));

Hope it helps someone.

You can not parse paginator object straight away (JMSSerializer is not prepared for that), do the following:

$paginatorResult->getIterator()->getArrayCopy()