[英]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.