Skip to content

Commit e36c246

Browse files
committed
minor tweaks
1 parent c176522 commit e36c246

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,14 @@ use Dunglas\DoctrineJsonOdm\Serializer;
4040
use Dunglas\DoctrineJsonOdm\Type\JsonDocumentType;
4141
use Symfony\Component\Serializer\Encoder\JsonEncoder;
4242
use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer;
43+
use Symfony\Component\Serializer\Normalizer\BackedEnumNormalizer;
4344
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
4445
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
4546

4647
if (!Type::hasType('json_document')) {
4748
Type::addType('json_document', JsonDocumentType::class);
4849
Type::getType('json_document')->setSerializer(
49-
new Serializer([new ArrayDenormalizer(), new DateTimeNormalizer(), new ObjectNormalizer()], [new JsonEncoder()])
50+
new Serializer([new BackedEnumNormalizer(), new DateTimeNormalizer(), new ArrayDenormalizer(), new ObjectNormalizer()], [new JsonEncoder()])
5051
);
5152
}
5253

@@ -215,7 +216,6 @@ For using the built-in type mapper:
215216
);
216217
```
217218

218-
219219
### Limitations when updating nested properties
220220

221221
Due to how Doctrine works, it will not detect changes to nested objects or properties.
@@ -292,21 +292,23 @@ class Kernel extends BaseKernel
292292

293293
**How can I add additional normalizers?**
294294

295-
The Symfony Serializer is easily extensible. This bundle registers and uses a service with ID `dunglas_doctrine_json_odm.serializer` as the serializer for the JSON type. This means we can easily override it in our `services.yaml` to use additional normalizers.
296-
As an example we use the Symfony `DateTimeNormalizer` service, so we do have support for any property that is an instance of `\DateTimeInterface`. Be aware that the order of the normalizers might be relevant depending on the normalizers you use.
295+
The Symfony Serializer is easily extensible. This bundle registers and uses a service with ID `dunglas_doctrine_json_odm.serializer` as the serializer for the JSON type.
296+
This means we can easily override it in our `services.yaml` to use additional normalizers.
297+
As an example we inject a custom normalizer service. Be aware that the order of the normalizers might be relevant depending on the normalizers you use.
297298

298299
```yaml
299300
# Add DateTime Normalizer to Dunglas' Doctrine JSON ODM Bundle
300301
dunglas_doctrine_json_odm.serializer:
301302
class: Dunglas\DoctrineJsonOdm\Serializer
302303
arguments:
303-
- ['@dunglas_doctrine_json_odm.normalizer.array', '@serializer.normalizer.datetime', '@dunglas_doctrine_json_odm.normalizer.object']
304+
- ['@App\MyCustom\Normalizer', '@?dunglas_doctrine_json_odm.normalizer.backed_enum', '@dunglas_doctrine_json_odm.normalizer.datetime', '@dunglas_doctrine_json_odm.normalizer.array', '@dunglas_doctrine_json_odm.normalizer.object']
304305
- ['@serializer.encoder.json']
306+
- '@?dunglas_doctrine_json_odm.type_mapper'
305307
public: true
308+
autowire: false
309+
autoconfigure: false
306310
```
307311

308-
As a side note: If you happen to use [Autowiring](https://symfony.com/doc/current/service_container/autowiring.html) in your `services.yaml` you might need to set `autowire: false` too. Same goes for `autoconfigure: false` in case you're using [Autoconfiguration](https://symfony.com/doc/current/service_container.html#the-autoconfigure-option).
309-
310312
**When the namespace of a used entity changes**
311313

312314
For classes without [type aliases](#using-type-aliases), because we store the `#type` along with the data in the database, you have to migrate the already existing data in your database to reflect the new namespace.
@@ -322,7 +324,7 @@ WHERE 'AppBundle\\\Entity\\\Bar' = JSON_EXTRACT(misc, '$."#type"');
322324

323325
## Credits
324326

325-
This bundle is brought to you by [Kévin Dunglas](https://dunglas.fr) and [awesome contributors](https://github.com/dunglas/doctrine-json-odm/graphs/contributors).
327+
This bundle is brought to you by [Kévin Dunglas](https://dunglas.dev) and [awesome contributors](https://github.com/dunglas/doctrine-json-odm/graphs/contributors).
326328
Sponsored by [Les-Tilleuls.coop](https://les-tilleuls.coop).
327329

328330
## Former Maintainers

src/Bundle/Resources/config/services.xml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@
55
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
66

77
<services>
8+
9+
<service id="dunglas_doctrine_json_odm.normalizer.backed_enum" class="Symfony\Component\Serializer\Normalizer\BackedEnumNormalizer" public="false" />
10+
11+
<service id="dunglas_doctrine_json_odm.normalizer.datetime" class="Symfony\Component\Serializer\Normalizer\DateTimeNormalizer" public="false" />
12+
13+
<service id="dunglas_doctrine_json_odm.normalizer.array" class="Symfony\Component\Serializer\Normalizer\ArrayDenormalizer" public="false" />
14+
15+
<service id="dunglas_doctrine_json_odm.type_mapper" class="Dunglas\DoctrineJsonOdm\TypeMapper" public="false" />
16+
817
<service id="dunglas_doctrine_json_odm.normalizer.object" class="Symfony\Component\Serializer\Normalizer\ObjectNormalizer" public="false">
918
<argument type="service" id="serializer.mapping.class_metadata_factory" on-invalid="ignore" />
1019
<argument>null</argument><!-- name converter -->
@@ -13,18 +22,10 @@
1322
<argument type="service" id="serializer.mapping.class_discriminator_resolver" on-invalid="ignore" />
1423
</service>
1524

16-
<service id="dunglas_doctrine_json_odm.normalizer.array" class="Symfony\Component\Serializer\Normalizer\ArrayDenormalizer" public="false" />
17-
18-
<service id="dunglas_doctrine_json_odm.normalizer.datetime" class="Symfony\Component\Serializer\Normalizer\DateTimeNormalizer" public="false" />
19-
20-
<service id="dunglas_doctrine_json_odm.normalizer.backed_enum" class="Symfony\Component\Serializer\Normalizer\BackedEnumNormalizer" public="false" />
21-
22-
<service id="dunglas_doctrine_json_odm.type_mapper" class="Dunglas\DoctrineJsonOdm\TypeMapper" public="false" />
23-
2425
<service id="dunglas_doctrine_json_odm.serializer" class="Dunglas\DoctrineJsonOdm\Serializer" public="true">
2526
<argument type="collection">
2627
<argument type="service" id="dunglas_doctrine_json_odm.normalizer.backed_enum" on-invalid="ignore" />
27-
<argument type="service" id="dunglas_doctrine_json_odm.normalizer.datetime" on-invalid="ignore" />
28+
<argument type="service" id="dunglas_doctrine_json_odm.normalizer.datetime" />
2829
<argument type="service" id="dunglas_doctrine_json_odm.normalizer.array" />
2930
<argument type="service" id="dunglas_doctrine_json_odm.normalizer.object" />
3031
</argument>

tests/Fixtures/AppKernel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ protected function configureContainer(ContainerBuilder $container, LoaderInterfa
4646
$container->loadFromExtension('framework', [
4747
'secret' => 'jsonodm',
4848
'test' => null,
49+
'http_method_override' => false,
4950
]);
5051

5152
$container->loadFromExtension('doctrine', [

0 commit comments

Comments
 (0)