Question

I am not getting all the attributes I would like to get serialized with FOSRestBundle. I'll try to simplify in the following example:

Imagine I have the following Entity Inheritance.

class Vehicle
{
    private $id;
    private $numberOfWheels;
}

class Car extends Vehicle
{
    private $numberOfDoors;
}

class MotorBike extends Vehicle
{
    private $handleBar;
}

If i do the following:

$myTransport = new MotorBike();
$myTransport -> setNumberOfWheels(2);
$myTransport -> setHandleBar("low");

When I try to serialize $myTransport with FOSRestBundle in a Controller I am only getting Vehicle attributes:

$view = View::create()->setFormat('json');
$view ->setData($myTranport);
return $this->get('fos_rest.view_handler')->handle($view);

This is what I am getting:

{
 id: 1,
 wheels: 2
}

Instead of getting all MotorBike attributes:

{
 id: 1,
 wheels: 2
 handleBar: "low"
}

How can I get all attributes? I also tried setting attributes as protected, but same result.

Kind Regards.

Was it helpful?

Solution

FOSRestBundle was working fine. The problem was I forgot to refresh the database/ORM with last changes. This did the trick:

console doctrine:schema:update --force

Kind Regards.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top