简体   繁体   English

Symfony2 FOSREST JMS \\ Serializer软件包错误

[英]Symfony2 FOSREST JMS\Serializer bundles error

Can you help to fix the following error? 您可以帮助解决以下错误吗?

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

This exception has been introduced in FOSRestBundle 2.0 (see here ) because of a serializer abstraction layer introduced in 2.0 too. 该异常已在FOSRestBundle 2.0中引入(请参阅此处 ),因为在2.0中也引入了序列化程序抽象层。 It is normally automatically managed by the bundle which detects the JMS serializer. 通常,它由检测JMS序列化程序的捆绑软件自动管理。

Did you add the JMSSerializerBundle to your kernel as following? 您是否按照以下说明将JMSSerializerBundle添加到内核中?

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

        // ...
    }
}

This should be the problem here. 这应该是这里的问题。

If it isn't, then maybe you tried to define directly the serializer FOSRestBundle uses, the following is a bad practice most of the time and should only be used if you know what you do : 如果不是,那么也许您尝试直接定义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 

If my second proposition is your case, you custom serializer has to implement the interface FOS\\RestBundle\\Serializer\\Serializer . 如果我的第二个建议是您的情况,则自定义序列化程序必须实现FOS\\RestBundle\\Serializer\\Serializer接口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM