JMSSerializer and FOSRestBundle - Annotations not working. "Does not exist"
Asked Answered
C

1

5

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
{
   ...
}
Chlorothiazide answered 26/4, 2013 at 5:24 Comment(0)
S
10

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.

Selfcontradiction answered 26/4, 2013 at 5:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.