I have a class which contains an imageBase64 property. This property is used when creating a new resource in a REST API, but should be excluded during serialization. Is this possible?
http://jmsyst.com/libs/serializer/master/cookbook/exclusion_strategies
in this case the most useful could be "groups"
I am aware of how to use exclusion strategies, but I think the only way to achieve my use case would be to add a group to all properties except for imageBase64, and to set this group on the serialization context during serialization only. This seems quite verbose to me, so let me rephrase my quesion: is there a more simple way to exclude this single propertly on serialization?
Ah, you can use the expression language exclusion strategy.
/*
* @Exclude(if="context.getDirection() === 1")
*/
private $img;
more info about it on http://jmsyst.com/libs/serializer/master/cookbook/exclusion_strategies#dynamic-exclusion-strategy
Ah yes, I already looked at the expression language but found it somewhat confusing. This is exactly what I needed. Thanks!
Most helpful comment
Ah, you can use the expression language exclusion strategy.
more info about it on http://jmsyst.com/libs/serializer/master/cookbook/exclusion_strategies#dynamic-exclusion-strategy