Jmsserializerbundle: Exclude property on serialization, but not on deserialization

Created on 29 Nov 2017  路  4Comments  路  Source: schmittjoh/JMSSerializerBundle

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?

Most helpful comment

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

All 4 comments

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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

simshaun picture simshaun  路  9Comments

priestor picture priestor  路  12Comments

CsabaNa picture CsabaNa  路  3Comments

yyaremenko picture yyaremenko  路  11Comments

kevinpapst picture kevinpapst  路  6Comments