Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JMSSerializer and FOSRestBundle - Annotations not working. "Does not exist"

I am trying to use ExclusionPolicy however I keep getting an "Annotation does not exist, or could not be auto-loaded" error.

Here is the exact error being thrown out:

[Semantical Error] The annotation "@JMS\SerializerBundle\Annotation\ExclusionPolicy" in class Acme\DemoBundle\Entity\Attributes does not exist, or could not be auto-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
{
   ...
}
like image 425
kfpmg Avatar asked Apr 26 '13 05:04

kfpmg


1 Answers

your problem is caused by using the wrong namespace.

Instead of:

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

It should be:

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

Notice "Bundle" is gone. In Ver 0.11 it was extracted to its own repository.

The changelog is as follows:

  • Namespace Changes

The core library has been extracted to a dedicated repository schmittjoh/serializer to make it easier re-usable in any kind of PHP project, not only in Symfony2 projects. This results in several namespace changes. You can adjust your projects by performing these replacements (in order):

  • JMS\SerializerBundle\Serializer -> JMS\Serializer
  • JMS\SerializerBundle -> JMS\Serializer
  • JMS\Serializer\DependencyInjection -> JMS\SerializerBundle\DependencyInjection

  • Dependency Changes

You might need to increase versions of jms/di-extra-bundle, and also jms/security-extra-bundle depending on your stability settings. Sometimes it is also necessary to run a composer update twice because of a bug in composer's solving algorithm.

like image 187
Kirill Fuchs Avatar answered Nov 02 '22 23:11

Kirill Fuchs