[英]Symfony2 FOSREST JMS\Serializer bundles 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
该异常已在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
接口。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.