Use Doctrine-JSON-ODM with JSM Serializer
vcastro45 opened this issue · 2 comments
Hello,
I use JMS Serializer in my project (so the Symfony's Serializer is disabled) and I'd like to use Doctrine-JSON-ODM but nothing explains how to do it.
The error displayed :
The service "dunglas_doctrine_json_odm.serializer" has a dependency on a no
!! n-existent service "serializer.property_accessor".
When I set an alias on dunglas_doctrine_json_odm.serializer
in services.yaml
like this:
services:
dunglas_doctrine_json_odm.serializer:
alias: jms_serializer
public: true
The error is now :
!!
!! Fatal error: Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Argument 1 passed to Dunglas\DoctrineJsonOdm\Type\JsonDocumentType::setSerializer() must implement interface Symfony\Component\Serializer\SerializerInterface, instance of JMS\Serializer\Serializer given, called in /var/www/html/backend/vendor/dunglas/doctrine-json-odm/src/Bundle/DunglasDoctrineJsonOdmBundle.php on line 36 in /var/www/html/backend/vendor/dunglas/doctrine-json-odm/src/Type/JsonDocumentType.php on line 65
!!
!! Symfony\Component\Debug\Exception\FatalThrowableError: Argument 1 passed to Dunglas\DoctrineJsonOdm\Type\JsonDocumentType::setSerializer() must implement interface Symfony\Component\Serializer\SerializerInterface, instance of JMS\Serializer\Serializer given, called in /var/www/html/backend/vendor/dunglas/doctrine-json-odm/src/Bundle/DunglasDoctrineJsonOdmBundle.php on line 36 in /var/www/html/backend/vendor/dunglas/doctrine-json-odm/src/Type/JsonDocumentType.php on line 65
!!
!! Call Stack:
!! 2.2013 37534088 1. Symfony\Component\Debug\ErrorHandler->handleException() /var/www/html/backend/vendor/symfony/debug/ErrorHandler.php:0
!!
!!
Is JSM Serializer incompatible with Doctrine-JSON-ODM ?
This library doesn't support JMS Serializer, and will not add support for it (it would increase the maintenance burden for no gains). Note that you can use both the Symfony Serializer and JMS Serializer in the same project.
This library supports any implementation of Symfony\Component\Serializer\Normalizer\NormalizerInterface
and Symfony\Component\Serializer\Normalizer\DenormalizerInterface
.
To use any custom serializer logic you should write a bridge class implementing the normalizer and denormalizer interfaces, and pass it to dunglas_doctrine_json_odm.serializer
.
I don't know it could be done for JMS Serializer.