nilportugues / symfony-jsonapi

JSON API Transformer Bundle for Symfony 2 and Symfony 3
http://nilportugues.com
MIT License
115 stars 19 forks source link

Using ramsey/uuid without calling toString gives an gives 'Array to string conversion' error #23

Closed ThomasBerends closed 8 years ago

ThomasBerends commented 8 years ago

I currently use Ramsey\Uuid for UUID generation.

I get an 'Array to string conversion' error. This happens when I put the following in my mapping file:

id_properties: - id

If you have any questions or would like to see the project, just comment. The project is a test project and doesn't contain any secret/business data, so I can safely share everything.

My entity (txt because Github doesn't accept php): Toilet.php

My mapping file (txt because Github doesn't accept yml): toilet.yml

Stacktrace here: stacktrace.txt

nilportugues commented 8 years ago

Well, that's because an ID has to be a string, not an array. Why don't you cast the UUID value to string? That would indeed solve the problem and it's the best option.

Second option is map the UUID with the other classes. That should obtain the UUID also.

nilportugues commented 8 years ago

@ThomasBerends yet I will add a fix to https://github.com/nilportugues/php-json-api/issues/69 to make sure no casting is required. Should not take long for the fix to be applied to the lib.

nilportugues commented 8 years ago

@ThomasBerends cast it to string... this is happening because Uuid::uuid4() is returning a value NOT storing it, therefore it will never work. Only possible solution is casting it to string.

By the way, I'm renaming the issue from "Using UUID's as ID's gives 'Array to string conversion' error" but "Using ramsey/uuid without calling toString gives an gives 'Array to string conversion' error", as that's what it is really happening.