Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single items returned inside arrays #95

Closed
driesvints opened this issue Aug 20, 2014 · 5 comments
Closed

Single items returned inside arrays #95

driesvints opened this issue Aug 20, 2014 · 5 comments

Comments

@driesvints
Copy link
Contributor

I know the tests are made up to expect this specific format but I cannot understand the reasoning behind it, nor can I find it back on the jsonapi.org website why it's made like this.

For example, in this test, you expect the following response:

{
    "book": [
        {
            "title": "Foo",
            "year": 1991
        }
    ],
    "linked": {
        "author": [
            {
                "name": "Dave"
            }
        ]
    }
}

Why is it like this? I would expect it to return the following when using Item:

{
    "book": {
        "title": "Foo",
        "year": 1991
    },
    "linked": {
        "author": {
            "name": "Dave"
        }
    }
}
@mediaholding
Copy link

You can create a new class which extends current serializer and use it for transformation:

class JsonApiSerializer extends \League\Fractal\Serializer\JsonApiSerializer {

    /**
     * Serialize an item resource
     *
     * @param string $resourceKey
     * @param array $data
     *
     * @return array
     */
    public function item($resourceKey, array $data)
    {
        return array($resourceKey ?: 'data' => $data);
    }
}

@brayniverse
Copy link

I was thrown off by this too.

@philsturgeon
Copy link
Member

This is #93 right?

@driesvints
Copy link
Contributor Author

Yes, sorry. Didn't realise that. It will definitely BC when you change this (and change the tests) so keep that in mind. You can close this in favour of 93 if you want.

@philsturgeon
Copy link
Member

Cheers. I bumped the issue and will merge when I get it, then release 0.10.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants