I am trying to serialize based on the groups that I have specified on my Product class. The full product class can be seen here. Here's the code that I am using following the example on the documentation here:
$serializer = $this->get('serializer');
$result = $serializer->serialize($param, 'json', SerializationContext::create()->setGroups(array('marketplace')));
So $param
above is essentially an array of Product objects.
However, for some reason this still outputs all of the Product attribute that I don't want (i.e: attribute that belongs to other groups not 'marketplace'). For example the attribute 'description'. I've marked description to be in the 'detail' group, but why is it still being returned as a part of the response when I asked for the 'marketplace' group?
/**
* @Groups({"detail"})
* @ORM\Column(name="description", type="string", length=350)
*/
protected $description;
Try to remove @ExclusionPolicy("none")
annotation.
You need use @ExclusionPolicy("all")
for class and @Expose
for each field you want to serialize.