Php Symfony2 FOSREST JMS\Serializer bundles错误

Php Symfony2 FOSREST JMS\Serializer bundles错误,php,symfony,fosrestbundle,jmsserializerbundle,Php,Symfony,Fosrestbundle,Jmsserializerbundle,您能帮助修复以下错误吗 InvalidArgumentException: "fos_rest.serializer" must implement FOS\RestBundle\Serializer\Serializer (instance of "JMS\Serializer\Serializer" given). in C:\wamp\www\SymfonyRestAPI\src\FOS\RestBundle\DependencyInjection\Compiler\SerializerC

您能帮助修复以下错误吗

InvalidArgumentException: "fos_rest.serializer" must implement FOS\RestBundle\Serializer\Serializer (instance of "JMS\Serializer\Serializer" given).
in C:\wamp\www\SymfonyRestAPI\src\FOS\RestBundle\DependencyInjection\Compiler\SerializerConfigurationPass.php line 58
at SerializerConfigurationPass->process(object(ContainerBuilder)) in C:\wamp\www\SymfonyRestAPI\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\Compiler\Compiler.php line 117
at Compiler->compile(object(ContainerBuilder)) in C:\wamp\www\SymfonyRestAPI\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\ContainerBuilder.php line 613
at ContainerBuilder->compile() in C:\wamp\www\SymfonyRestAPI\app\bootstrap.php.cache line 2502
at Kernel->initializeContainer() in C:\wamp\www\SymfonyRestAPI\app\bootstrap.php.cache line 2281
at Kernel->boot() in C:\wamp\www\SymfonyRestAPI\app\bootstrap.php.cache line 2312
at Kernel->handle(object(Request)) in C:\wamp\www\SymfonyRestAPI\web\app_dev.php line 28

FOSRestBundle 2.0(请参阅)中引入了此异常,因为2.0中也引入了序列化程序抽象层。 它通常由检测JMS序列化程序的捆绑包自动管理

您是否将JMSSerializerBundle添加到内核中,如下所示

// app/AppKernel.php
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new JMS\SerializerBundle\JMSSerializerBundle(),,
        );

        // ...
    }
}
这应该是这里的问题

如果不是,那么可能您试图直接定义序列化程序FOSRestBundle使用的,以下大多数情况下都是错误的做法,只有在您知道自己在做什么时才应该使用:

// services.yml
services:
    fos_rest.serializer:
        // This won't work in case your class doesn't
        // implement FOS\RestBundle\Serializer\Serializer
        class: My\Serializer 

如果我的第二个建议是您的情况,那么定制序列化程序必须实现接口
FOS\RestBundle\serializer\serializer

,这太宽泛了。但我认为您必须添加配置文件的代码。哪个类与“fos_rest.serializer”相关?我遵循symfony教程的所有步骤,但始终存在相同的错误,在appKernel.php文件中,我添加了新的fos\RestBundle\FOSRestBundle(),在composer.json中添加了新的JMS\SerializerBundle\JMSSerializerBundle(),我添加了“friendsofsymfony/rest bundle”:“0.11.*”,“jms/serializer bundle”:“0.12.x-dev”,但同样的错误请在答案中添加您的注释内容。您应该提供一个@GitaarLAB您是对的,谢谢您的注释。您是如何做到的?请在您的答案中解释它?抱歉,我的意思是这可能是导致此错误发生的原因,我将改进我的答案。