I've been doing some research without any result. So I come here to ask directly the question.
I have an entity, in order to return it into some api call, I need to serialize it.
For now I have something like that
class Place implements \JsonSerializable{
[...] fields lists [...]
public function jsonSerialize(){
return array(
"id" => $this->id,
"title" => $this->title);
}
}
This is working right, but, i would like to be able to have multiple definition for the serialization because for the api1 I might want to return id and title, but may be for the api2 I would like to return id / title and resume.
Is there a way to make a condition into the jsonSerialize() ? Or some other way ? I'm pretty sure I already have done something like that in Java, that might be possible in php.
Thanks for your help.