diff --git a/README.md b/README.md index edec8d0..aa14d66 100644 --- a/README.md +++ b/README.md @@ -250,7 +250,7 @@ As an example we use the Symfony `DateTimeNormalizer` service so we do have supp dunglas_doctrine_json_odm.serializer: class: Dunglas\DoctrineJsonOdm\Serializer arguments: - - ['@serializer.denormalizer.array', '@serializer.normalizer.datetime', '@serializer.normalizer.object'] + - ['@dunglas_doctrine_json_odm.normalizer.array', '@serializer.normalizer.datetime', '@dunglas_doctrine_json_odm.normalizer.object'] - ['@serializer.encoder.json'] public: true ``` diff --git a/src/Bundle/Resources/config/services.xml b/src/Bundle/Resources/config/services.xml index 64fa999..c50abbd 100644 --- a/src/Bundle/Resources/config/services.xml +++ b/src/Bundle/Resources/config/services.xml @@ -5,10 +5,20 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> + + + null + + + + + + + - - + + diff --git a/tests/FunctionalTest.php b/tests/FunctionalTest.php index 93bb1cb..ad5c5a9 100644 --- a/tests/FunctionalTest.php +++ b/tests/FunctionalTest.php @@ -162,4 +162,37 @@ public function testNullIsStoredAsNull() $this->assertNull($stmt->fetch()['attributes']); } + + public function testStoreAndRetrieveDocumentWithInstantiatedOtherSerializer() + { + /** + * This call is necessary to cover this issue. + * + * @see https://github.com/dunglas/doctrine-json-odm/pull/78 + */ + $serializer = self::$kernel->getContainer()->get('serializer'); + + $attribute1 = new Attribute(); + $attribute1->key = 'foo'; + $attribute1->value = 'bar'; + + $attribute2 = new Attribute(); + $attribute2->key = 'weights'; + $attribute2->value = [34, 67]; + + $attributes = [$attribute1, $attribute2]; + + $product = new Product(); + $product->name = 'My product'; + $product->attributes = $attributes; + + $manager = self::$kernel->getContainer()->get('doctrine')->getManagerForClass(Product::class); + $manager->persist($product); + $manager->flush(); + + $manager->clear(); + + $retrievedProduct = $manager->find(Product::class, $product->id); + $this->assertEquals($attributes, $retrievedProduct->attributes); + } }