Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

denormalizers are no longer aliased as normalizer in 4.4

オープン
#8,550 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
68/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
php, symfony
領域
api, backend

調査の方向性

Start by reviewing commit d36c14c and the service IDs api_platform.jsonld.normalizer.item and api_platform.jsonld.denormalizer.item. Reproduce the issue with the DTO and decorator shown, then verify that decorating the normalizer also affects denormalization as it did in 4.3, without requiring a second decorator.

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
PHP
スター
2.6k
フォーク
982
平均マージ
1日 16時間
マージ済み PR(30日)
59

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

api-platform/core のほかの issue

api-platform/core の issue をすべて見る

似ている issue

PHP の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。