I have a $character property in my entity Foo.
The property is an entity itself (AppBundle\Entity\Character).
When I serialize Foo, I don't want to have the whole entity Character to be serialized: I need just the nickname of the Character.
I wrote this in AppBundle\Entity\Foo:
/**
*
* @Serializer\VirtualProperty()
* @Serializer\SerializedName("character")
*/
public function getCharacterNickname()
{
return $this->character->getNickname();
}
The "virtual property" annotation works.
But the "serializedName" doesn't, because the result is the following:
{
"id": 18,
"characterNickname": "Mr.Gilbert Norrel",
"foo": "foo",
"bar": true,
"baz": "baz"
}
("characterNickname" instead of just "character", as I asked in the annotation).
The properties "id", "foo", "bar" and "baz" have the annotation @Serializer\Expose(). The property "character" doesn't (because I want to serialize THAT property via the VirtualProperty)
What am I missing? Is it caused by the fact that I want to serialize the property with the name of an existing property?
Ty :)
Found the solution:
https://github.com/schmittjoh/serializer/issues/334
It seems that there's an error in the IdenticalPropertyNamingStrategy file of the library.