Skip to content

Decorating all item normalizers on master branch #2316

Closed
@silverbackdan

Description

@silverbackdan

Would anyone be able to give a quick example of how to create a custom item normalizer using the current master branch?

It can be done as documented, but there are issues.

  1. If you document the item normalizer as documented, you need to add a priority at 8 or higher. This is to make sure it is called over the other item normalizers (jsonld, graphql etc.)
  2. Once that is done, the new normalizer will be called and the additional array keys (e.g. @id) are not added.

The solution to this is to instead decorate the jsonld item normalizer, but then this normalizer wouldn't work if I wanted the response in another format (e.g. xml). I'm in a position with my project that json alone is fine, but it seems like a new bug would be introduced if the current master branch were to be released.

Would it be possible and appropriate to update the service definition for the item normalizer that is documented to be used to be whichever item normalizer is going to be used on the current request? E.g. a jsonld request will make the api_platform.serializer.normalizer.item service definition an alias for api_platform.jsonld.normalizer.item and therefore decorating api_platform.serializer.normalizer.item would still work no matter what format the response should be in. I'm not sure how to go about implementing this or if that is required. It could be that custom normalizers just need to be implemented slightly differently to how it is currently documented for the changes in the master branch.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions