PHP code example of softfineware / discriminator-default-normalizer
1. Go to this page and download the library: Download softfineware/discriminator-default-normalizer library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
softfineware / discriminator-default-normalizer example snippets
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 {}
\Symfony\Component\Serializer\Normalizer\ObjectNormalizer::class