JMS Serializer: dynamically changing the name of a virtual object at runtime

I am using JMS Serializer Bundle and Symfony2. I am using VirtualProperties. I am currently setting the property name using the SerializedName annotation.

 /**
 * @JMS\VirtualProperty()
 * @JMS\SerializedName("SOME_NAME")
 */
public function getSomething()
{
    return $this->something
}

Is it possible to dynamically set a serialized name inside a function? Or can you dynamically influence a name using Post / Pre serialization events?

Thank!

+4
source share
2 answers

, , - , , . , null JMS.

0

, , :

$this->serializer = SerializerBuilder::create()->setPropertyNamingStrategy(new IdenticalPropertyNamingStrategy())->build();

$json = $this->serializer->serialize($object, 'json');
dump($json);
0

All Articles