tobyzerner / json-api-php

JSON-API (http://jsonapi.org) responses in PHP.
MIT License
436 stars 79 forks source link

Getting a "Failed calling Tobscure\JsonApi\Document::jsonSerialize()" error #102

Closed rafatrace closed 8 years ago

rafatrace commented 8 years ago

Hi, I'm getting this error, maybe someone face this before.

This is my UserSerializer:

class UserSerializer extends AbstractSerializer
{
    protected $type = 'user';

    public function getAttributes($item, array $fields = null)
    {
        return [
            'id' => $item->id,
            'name' => $item->name,
            'email' => $item->email
        ];
    }
}

And this is the example I'm trying to get to work:

$user = new \stdClass();
$user->id = 24;
$user->name = 'Hello World';
$collection = new Collection([$user], new UserSerializer);

$document = new Document($collection);

echo json_encode($document);

Am I doing something wrong?

tobyzerner commented 8 years ago

I'm unable to reproduce this using your code sample. What version of json-api + PHP are you using?

rafatrace commented 8 years ago

Sorry for not coming back sooner, I got it working. Structure error