I have a method that returns a value:
/**
* @ORM\Table()
* @ORM\Entity(repositoryClass="PersonRepository")
*/
class Person {
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
public function getFoo(){
return $this->id + 1;
}
//setters & getters
}
I would like to include the value that getFoo()
returns when I serialize a Person
object so that it would look like this:
{
'id' : 25
'foo' : 26
}
You need to set
@VirtualProperty
and@SerializedName
.You can read more about it here: http://jmsyst.com/libs/serializer/master/reference/annotations
Pay attention that this only works for serialization and not for deserialization.