JMS Serializer: serialize camel-cased fields without them being renamed

Using JMSSerializer (or its bundle) serialized field are renamed by default to the underscore-separated words naming convention. If like me you prefer camel-case naming and you want fields serialized as it, there’s two solutions.

1. Set serialize name for each fields

You can use the @SerializedName annotation, serialized-name XML property or the serialized_name YAML configuration to fix the name that will be used for each fields.

2. Change the whole naming strategy

If like me you don’t want to set the serialized name for each field, you can change the naming strategy by your custom one or the simple IdenticalPropertyNamingStrategy that don’t rename fields.

The first solution is to set the naming strategy while creating your serializer using the SerializerBuilder:

The second solution if you use the bundle is to override the jms_serializer.camel_case_naming_strategy.class parameter in your app/config/parameters.yml file.

facebooktwittergoogle_plusredditpinterestlinkedinmail