You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Serializer documentation can be improved (possibly contains an error?) #2280
2 part question, both relating to (Symfony) Serializer docs.
1:
The Serializer docs show an example of decorating the json-ld normalizer to add a few fields, but wouldn't a completely custom serializer be better so the getSupportedTypes can be used to efficiently decide if this serializer should be used instead of having 20,30, maybe 100s of services decorating the json-ld normalizer and it having to go through all those layers with like if (!$data instanceof ...) or if (!is_a($type, SomeClass::class, true))
Should we add an example for a cache-able/scalable solution that doesn't involve decorating the json-ld one?
Returning true on getSupportedTypes means the usage of the serializer gets cached, and the supportsNormalization method is only checked once, then never again. So adding the self::ALREADY_CALLED in the normalize method doesn't do anything,... next time it goes through this normalizer, the supportsNormalization is skipped and boom, it now executed normalize on an item that has possibly already gone through it?
I can contribute a change for both things, but would like to get a second opinion first to see if I'm maybe missing something.
Additionally, if we do want to show off the decorated serializer, which is super helpful for creating generic serializers that need to apply to all entities instead of 1 specific resource, should we simplify the docs to use attributes to decorate/inject decorated instead of yaml config? Api-platform's lowest Symfony requirement already supports these attributes.
Activity
jannes-io commentedon Mar 31, 2026
Additionally, if we do want to show off the decorated serializer, which is super helpful for creating generic serializers that need to apply to all entities instead of 1 specific resource, should we simplify the docs to use attributes to decorate/inject decorated instead of yaml config? Api-platform's lowest Symfony requirement already supports these attributes.
wdttilburg commentedon Sep 15, 2026
I ran into issue #2 as well. I believe it should be changed to false as well.