public function serialize($object, array $serializationGroups)
{
$serializer = SerializerBuilder::create();
$serializer->setPropertyNamingStrategy(new SerializedNameAnnotationStrategy(new IdenticalPropertyNamingStrategy()));
$serializer->addMetadataDir($this->configDir . "/serializer", 'App\Entity');
$serializer->setCacheDir($this->cacheDir . "/jms_serializer");
$serializer = $serializer->build();
$group = new GroupsExclusionStrategy($serializationGroups);
$context = SerializationContext::create();
$context->addExclusionStrategy($group);
return $serializer->serialize($object, 'json', $context);
}
It will make JSON string where property field is camelCased instead of Snake_cased. I highly recommend to use 'App\Entity' in addMetadataDir() because by default in Symfony jms_serializer.yaml config is set 'namespace_prefix' in metadata node, and without 'App\Entity' argument YML/XML entity configs won't work. It is also example how to customize Serializer parameters manually with SerializerBuilder without framework config.