Stormsson
Stormsson

Reputation: 1551

JMS Serializer Bundle - Create group at runtime

I'm trying to obtain a sort of custom API creation by allowing the user to select which fields to serialize from a web interface.

One possible solution could be to allow the user to create the equivalent of JMS Serialization groups.

Is there some way to configure a JMS Group at runtime so i can call the following ?

$serializer->serialize(new X(), 'json', SerializationContext::create()->setGroups(array('my_custom_group')));

Upvotes: 2

Views: 311

Answers (1)

LBA
LBA

Reputation: 4109

You can use the

 interface ExclusionStrategyInterface
 {
   public function shouldSkipClass(ClassMetadata $metadata, Context $context);
   public function shouldSkipProperty(PropertyMetadata $property, Context $context);
 }

A very extensive example how this can be used please check this link:

http://jolicode.com/blog/how-to-implement-your-own-fields-inclusion-rules-with-jms-serializer

Upvotes: 1

Related Questions