softfineware / discriminator-default-normalizer-bundle
Installs: 5
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 1
Open Issues: 0
Language:Makefile
Requires
- php: ^8.1
- softfineware/discriminator-default-normalizer: ^1.1
- symfony/symfony: ^6.1
Requires (Dev)
- roave/security-advisories: dev-latest
- symfony/test-pack: ^1.0
README
How to use it
use SoftFineWare\SerializerDiscriminatorDefault\Attributes\DiscriminatorDefault; use Symfony\Component\Serializer\Annotation\DiscriminatorMap; #[DiscriminatorDefault(class: DefaultRequest::class)] #[DiscriminatorMap(typeProperty: 'type', mapping: [ 'a' => ARequest::class, ])] abstract class BaseRequest { public function __construct( public readonly string $id, public readonly string $type ) { } } class DefaultRequest extends BaseRequest {}
In case of no match json will de denormalized to default class specifing by DiscriminatorDefault
attribute
DiscriminatorDefault
should not point to a class with DiscriminatorMap
new child class must be create as DefaultRequest
above
Installation
This normalizer must have priority -999 before:
\Symfony\Component\Serializer\Normalizer\ObjectNormalizer::class