sidus / base-serializer-bundle
Additional serializer features for Symfony 3 & 4
Installs: 8 642
Dependents: 1
Suggesters: 1
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=5.6
- sidus/base-bundle: ~1.0
- symfony/serializer: >2.4,<5.0
This package is auto-updated.
Last update: 2024-10-21 20:36:30 UTC
README
Serializer
The NestedPropertyDenormalizer can be very useful for denormalizing API responses into proper model entities, it works without any setters and can denormalize embed data and embed entity collections based on very simple annotations.
This denormalizer will only work on PHP classes with the @NestedPropertyDenormalizer
annotation.
Configuration
Configuration example
<?php namespace FooBar\Model; use Sidus\BaseSerializerBundle\Serializer\Annotation\NestedClass; use Sidus\BaseSerializerBundle\Serializer\Annotation\NestedPropertyDenormalizer; /** * @NestedPropertyDenormalizer() */ class Book { /** @var string */ protected $id; /** * @var \DateTimeInterface|null * * @NestedClass(targetClass="DateTime") */ protected $publicationDate; /** * @var Author|null * * @NestedClass(targetClass="FooBar\Model\Author") */ protected $author; /** * @var Edition[] * * @NestedClass(targetClass="FooBar\Model\Edition", multiple=true) */ protected $editions = []; // Here be getters (no setters needed) }
Note that the @NestedClass
annotation can target any class.
Additional services
This bundle also features additional services that can be used by other bundles. Implementation details are not provided as they are only needed in custom normalizers.