JMSSerializer and FOSRestBundle - annotations do not work. "Does not exist"

I try to use ExclusionPolicy, but I keep getting the error "Annotations do not exist or cannot be loaded automatically."

Here is the exact error:

[Semantic error] The annotations "@JMS \ SerializerBundle \ Annotation \ ExclusionPolicy" in the class Acme \ DemoBundle \ Entity \ Attributes does not exist or cannot be automatically loaded.

My code is as follows:

namespace Acme\DemoBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints;
use JMS\SerializerBundle\Annotation\ExclusionPolicy;
use JMS\SerializerBundle\Annotation\Expose;

/**
 * Acme\DemoBundle\Entity\Attributes
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="Acme\DemoBundle\Entity\AttributesRepository")
 * 
 * @ExclusionPolicy("all")
 */
class Attributes
{
   ...
}
+5
source share
1 answer

Your problem is caused by the wrong namespace.

Instead:

use JMS\SerializerBundle\Annotation\ExclusionPolicy;
use JMS\SerializerBundle\Annotation\Expose;

It should be:

use JMS\Serializer\Annotation\ExclusionPolicy;
use JMS\Serializer\Annotation\Expose;

The Bundle notification has disappeared. In Ver 0.11, it was checked out in its own repository.

:

schmittjoh/serializer, PHP Symfony2. . , ( ):

  • JMS\SerializerBundle\ β†’ JMS\
  • JMS\SerializerBundle β†’ JMS\Serializer
  • JMS\Serializer\DependencyInjection β†’ JMS\SerializerBundle\DependencyInjection

jms/di-extra-bundle, jms/security-extra-bundle . , .

+10

All Articles