I am modifying an API that uses Symfony 2.7 and JMS Serializer. I have an entity that includes some image data. In my entity definition, the relevant field is annotated as follows:
/**
* @var string
*
* @ORM\Column(name="images_data", type="text")
* @JMS\Groups({"default", "playlist", "digital_signage", "distributed_item"})
* @JMS\Type("array")
* @JMS\Accessor(getter="getImagesDataDecode")
* @JMS\SerializedName("imagesData")
*/
private $imagesData;
... and I have changed the getImagesDataDecode() method to look like this:
public function getImagesDataDecode()
{
return ['testone'=>'a','testtwo'=>'b'];
}
... but during testing, my API endpoint does not return the new test array. I can only conclude that the getImagesDataDecode() method is not being used during the API response.
How do I find out which method is being used to return API data?
I hope to make my program do a bit of analysis and filtering before returning the data in question. Without a place to insert that logic, it looks like I'm temporarily out of luck.
You are missing the @JMS\AccessType
annotation to tell the serializer to use your Accessor method. It defaults to property
and therefore it doesn't use any methods, it uses the property itself through a reflection.
https://jmsyst.com/libs/serializer/master/reference/annotations#accesstype