JMS Serializer: how to use camel case for properties
I found a way to do it globally, if you want to keep the property names as is you need to use the IdenticalPropertyNamingStrategy
There are several ways to accomplish this, first by changing the config(Thanks @Phantom):
#config.ymljms_serializer: property_naming: id: 'jms_serializer.identical_property_naming_strategy'
Second, you could override the default alias for this
services: jms_serializer.naming_strategy: alias: jms_serializer.identical_property_naming_strategy
The bundle defines these https://github.com/schmittjoh/JMSSerializerBundle/blob/master/Resources/config/services.xml so you should be able to override them
Another way to do it is when you initialize the builder:
$serializebuilder = JMS\Serializer\SerializerBuilder::create();$serializebuilder->setPropertyNamingStrategy(new \JMS\Serializer\Naming\IdenticalPropertyNamingStrategy());$serializer = $serializebuilder->build();
Having upgraded jms/serilizer-bundle from 1.1 to 2.2 the parameter hack described above did not work. You can override the service definition as follows:
#app/config/services.ymlservices: .... jms_serializer.serialized_name_annotation_strategy: class: JMS\Serializer\Naming\SerializedNameAnnotationStrategy arguments: - '@jms_serializer.identical_property_naming_strategy'
Worked for me (Symfony 4.4 and JMS ^3.8) with this config in config/packages/jms_serializer.yaml
:
jms_serializer: property_naming: id: jms_serializer.identical_property_naming_strategy
and removing the cache manually