gpt4 book ai didi

php - JMSSerializer 和 FOSRestBundle - 注释不起作用。 "Does not exist"

转载 作者:可可西里 更新时间:2023-11-01 13:45:24 26 4
gpt4 key购买 nike

我正在尝试使用 ExclusionPolicy,但我不断收到“注释不存在或无法自动加载”错误。

这是抛出的确切错误:

[Semantical Error] The annotation "@JMS\SerializerBundle\Annotation\ExclusionPolicy" in class Acme\DemoBundle\Entity\Attributes does not exist, or could not be auto-loaded.

我的代码如下:

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
{
...
}

最佳答案

您的问题是由使用错误的命名空间引起的。

代替:

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

应该是:

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

注意“Bundle”不见了。在 Ver 0.11它被提取到自己的存储库中。

变更日志如下:

  • 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.

关于php - JMSSerializer 和 FOSRestBundle - 注释不起作用。 "Does not exist",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16229299/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com