API Platform version(s) affected: 4.4.0
Description
Commit d36c14c splits normalizer and denormalizer into dedicated ItemNormalizer and ItemDenormalizer. This causes overwritten decorators to no longer work (docs is also still outdated https://api-platform.com/docs/v4.4/core/serialization/#decorating-a-serializer-and-adding-extra-data-for-symfony)
How to reproduce
Create a serializer that decorates only 'api_platform.jsonld.normalizer.item', it no longer decorates during denormalize.
// small DTO to play with:
class Test
{
public bool $test = false;
}
#[AsDecorator('api_platform.jsonld.normalizer.item')]
class ExampleSerializer implements NormalizerInterface, DenormalizerInterface, SerializerAwareInterface
{
public function __construct(
#[AutowireDecorated]
private readonly NormalizerInterface&DenormalizerInterface&SerializerAwareInterface $decorated,
) {
}
public function setSerializer(SerializerInterface $serializer): void
{
$this->decorated->setSerializer($serializer);
}
public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed
{
$result = $this->decorated->denormalize($data, $type, $format, $context);
$result->test = true;
return $result;
}
public function supportsDenormalization(
mixed $data,
string $type,
?string $format = null,
array $context = [],
): bool {
return $this->decorated->supportsDenormalization($data, $type, $format, $context);
}
public function normalize(
mixed $data,
?string $format = null,
array $context = [],
): array|string|int|float|bool|ArrayObject|null {
$result = $this->decorated->normalize($data, $format, $context);
$result['extraProperty'] = true;
return $result;
}
public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
{
return $this->decorated->supportsNormalization($data, $format, $context);
}
public function getSupportedTypes(?string $format): array
{
return $this->decorated->getSupportedTypes($format);
}
}
Given this setup, I expect normalize to add extraProperty and denormalize to set test to true. In 4.3 this worked, in 4.4 it no longer works and we have to add an extra decorator:
~ #[AsDecorator('api_platform.jsonld.normalizer.item')]
+ #[AsDecorator('api_platform.jsonld.denormalizer.item')]
~ class ExampleSerializer implements NormalizerInterface, DenormalizerInterface, SerializerAwareInterface
Hence why this is a backwards compatibility break on a minor version (4.4).
Possible Solution
d36c14c should be removed from 4.4 and moved to 5.0
Additional Context
API Platform version(s) affected: 4.4.0
Description
Commit d36c14c splits normalizer and denormalizer into dedicated
ItemNormalizerandItemDenormalizer. This causes overwritten decorators to no longer work (docs is also still outdated https://api-platform.com/docs/v4.4/core/serialization/#decorating-a-serializer-and-adding-extra-data-for-symfony)How to reproduce
Create a serializer that decorates only
'api_platform.jsonld.normalizer.item', it no longer decorates during denormalize.Given this setup, I expect normalize to add
extraPropertyand denormalize to settestto true. In 4.3 this worked, in 4.4 it no longer works and we have to add an extra decorator:~ #[AsDecorator('api_platform.jsonld.normalizer.item')] + #[AsDecorator('api_platform.jsonld.denormalizer.item')] ~ class ExampleSerializer implements NormalizerInterface, DenormalizerInterface, SerializerAwareInterfaceHence why this is a backwards compatibility break on a minor version (4.4).
Possible Solution
d36c14c should be removed from 4.4 and moved to 5.0
Additional Context