Serialization error with custom getter

563 views Asked by At

I have an entity with two manyToOne that a want to wrap during serialization.

namespace AppBundle\Entity\Fleet;

use AppBundle\Entity\Account\Site;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 */
class Equipment
{
    /**
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Account\Site")
     * @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
     */
    protected $siteOwner;

    /**
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\Account\Contact")
     * @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
     */
    protected $contactOwner;
}

Serialized into

{
    "owner": {
        "site": {...},
        "contact": {...}
    }
}

So I made a simple getter.

/**
 * @Groups({"read"})
 */
public function getOwner()
{
    return [
        'site' => $this->siteOwner,
        'contact' => $this->contactOwner,
    ];
} 

Site and Contact entities are also ApiResource with working endpoints. But I get an error during serialization : No resource class found for object of type "AppBundle\Entity\Account\Site".

Any idea ?

Update

I was able to reproduce the same problem with the api-platform demo. I have forked the base demo, and added a custom getter on the review entity.

Got the same No resource class found for object of type AppBundle\Entity\Book

0

There are 0 answers