Skip to content

JsonApi attributes are missing when using an Output class #3590

Closed
@ibrcko

Description

@ibrcko

API Platform version(s) affected: 2.5.6

Description
Hi, I have a concern that Json:Api response formatting isn’t working properly if an output class is being used for API resource (“relationships”, “links”, “meta”, "included" fields are missing)

A check if the output class is being used is performed here:

if (null !== $this->getOutputClass($this->getObjectClass($object), $context)) {

and if it is, an AbstractItemNormalizer->normalize() method is called.
Data is then transformed and execution proceeds as such:

AbstractItemNormalizer->normalize() => 
Symfony/Serializer->normalize() =>
JsonApi/ObjectNormalizer->normalize()

In the JsonApi/ObjectNormalizer->normalize() Json:Api specific fields are added (“id”, “type”, “attributes”)
My concern is that the code below the if-statement linked above never gets executed.

This results in the resource metadata (links, meta, relationships) not being applied to the response object.

Can someone please help understand is this actually the case or I’m misinterpreting something?
Thanks 😃

How to reproduce

  1. Mark an API resource with "output" option
  2. Add an OutputTransformer that creates an output class and returns it
  3. Send GET request to retrieve your resource with a header "accept":"application/vnd.api+json"

If these steps are not enough, I can provide code snippets.

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