Symfony 3.4 JMS Serializer DoctrineObjectConstructor::__construct() 期望 ManagerRegistry,给定 Doctrine\Bundle\DoctrineBundle\Registry 的实例

Symfony 3.4 JMS Serializer DoctrineObjectConstructor::__construct() expect ManagerRegistry, instance of Doctrine\Bundle\DoctrineBundle\Registry given

请帮帮我,我卡在这里了。我最近将 Symfony 版本从 2.8 升级到 Symfony 3.4 LTS 版本。除了我在自定义控制器上扩展 Sonata\UserBundle\Controller\Api\UserController 的 Rest API 端点外,一切正常。当我 运行 API 我得到以下错误

Type error: Argument 1 passed to JMS\Serializer\Construction\DoctrineObjectConstructor::__construct() must be an instance of Doctrine\Persistence\ManagerRegistry, instance of Doctrine\Bundle\DoctrineBundle\Registry given, called in /var/www/html/var/cache/dev/Container9bzqz8e/appDevDebugProjectContainer.php on line 3303

升级后开始出现这种情况。

我的控制器

use FOS\RestBundle\View\View;
use Sonata\UserBundle\Controller\Api\UserController as SonataUserController;
use League\Fractal\Manager;
use League\Fractal\Resource\Item;

class CustomerUserController extends SonataUserController {
protected $formFactory;

/**
 * @var CustomerUserService
 */
private $customerUserService;

/**
 * @var Manager
 */
private $fractal;

/**
 * CustomerUserController constructor.
 * @param UserManagerInterface $userManager
 * @param FormFactory $formFactory
 * @param CustomerUserService $customerUserService
 * @param LoggerInterface $logger
 * @param GroupManagerInterface $groupManager
 */
public function __construct(
    UserManagerInterface $userManager,
    FormFactory $formFactory,
    CustomerUserService $customerUserService,
    LoggerInterface $logger,
    GroupManagerInterface $groupManager
) {
    parent::__construct($userManager, $groupManager, $formFactory);

    $this->formFactory = $formFactory;
    $this->customerUserService = $customerUserService;
    $this->fractal = new Manager();
    $this->logger = $logger;
    $this->fractal->setSerializer(new CleanCollectionArraySerializer());
}

/**
 * Retrieves a specific CustomerUser
 *
 * @param integer $id
 * @return array
 */
public function getUserAction($id)
{
    /** @var User $user */
    $user = parent::getUserAction($id);
    $this->ensureUserIsCustomerUser($user);

    $this->fractal->parseIncludes('customer');
    $userObject = new Item($user, new UserTransformer());
    return $this->fractal->createData($userObject)->toArray();
}}

作曲者信息

我只添加了相关的包

doctrine/annotations                     1.10.3          
doctrine/cache                           1.10.2          
doctrine/collections                     1.6.6           
doctrine/common                          v2.8.1          
doctrine/data-fixtures                   1.3.3           
doctrine/dbal                            v2.6.3          
doctrine/doctrine-bundle                 1.10.3          
doctrine/doctrine-cache-bundle           1.4.0           
doctrine/doctrine-fixtures-bundle        v2.4.1          
doctrine/doctrine-migrations-bundle      v1.3.2          
doctrine/inflector                       1.4.3           
doctrine/instantiator                    1.0.5           
doctrine/lexer                           1.2.1           
doctrine/migrations                      v1.8.1          
doctrine/orm                             v2.5.14
friendsofsymfony/rest-bundle             2.8.1           
friendsofsymfony/user-bundle             v2.1.2
jms-serializer/serializer                1.3.0           
jms/metadata                             1.7.0           
jms/parser-lib                           1.0.0           
jms/serializer                           1.14.1          
jms/serializer-bundle                    2.4.4
sonata-project/user-bundle               4.5.1

Config.yaml

jms_serializer:
    metadata:
        directories:
            AppUserBundle:
                namespace_prefix: "App\UserBundle"
                path: "@AppUserBundle/Resources/config/serializer"
            SonataUserBundle:
                namespace_prefix: "Sonata\UserBundle"
                path: "@AppUserBundle/Resources/config/serializer"
            FOSUserBundle:
                namespace_prefix: "FOS\UserBundle"
                path: "@AppUserBundle/Resources/config/serializer"


fos_rest:
    param_fetcher_listener: true
    body_listener:          true
    format_listener:        true
    view:
        view_response_listener: 'force'
        formats:
            json: true
        force_redirects:
            html: true
            json: true
    routing_loader:
        default_format: json
    body_converter:
        enabled: true
        validate: true
    disable_csrf_role: ROLE_API
    exception:
        enabled: true
        messages:
            'App\UserBundle\Controller\Api\Exception': true

序列化器Entity.User.yaml 文件

Sonata\UserBundle\Model\User:
    exclusion_policy: ALL
    properties:
        firstname:
            expose: true
            groups: [sonata_api_read, sonata_api_write]
        lastname:
            expose: true
            groups: [sonata_api_read, sonata_api_write]

FOS\UserBundle\Model\User:
    exclusion_policy: ALL
    properties:
        id:
            expose: true
            groups: [sonata_api_read, sonata_api_write]
        username:
            expose: true
            skip_when_empty: true
            groups: [sonata_api_read, sonata_api_write]
        email:
            expose: true
            skip_when_empty: true
            groups: [sonata_api_read, sonata_api_write]
        enabled:
            expose: true
            groups: [sonata_api_read, sonata_api_write]
        locked:
            expose: true
            groups: [sonata_api_read, sonata_api_write]
        expired:
            expose: true
            groups: [sonata_api_read, sonata_api_write]
        credentialsExpired:
            expose: true
            skip_when_empty: true
            groups: [sonata_api_read, sonata_api_write]

非常感谢任何帮助。

我通过显式添加

设法解决了这个问题

"jms/serializer-bundle": "^1.0 | ^2.4"

在我的 composer.json 文件中。

希望这对某人有所帮助