JMS Serializer: How to Use Camel Body for Properties

I use FOS Rest bundle and JMS Serializer to create REST Api. The problem is that I would like to keep the property names in the returned JSON camel, instead of using _.

For example, I have a property called employeeIdentifier, which by default translates to employee_identifier.

I saw that there is an option in the configuration to disable the lowercase letter and get rid of _, but then it becomes an EmployeeIdentifier.

Is there a way that the JMS Serializer keeps the original property name? thanks in advance

+4
source share
2 answers

, , IdenticalPropertyNamingStrategy

services:
    jms_serializer.naming_strategy:
        alias: jms_serializer.identical_property_naming_strategy

https://github.com/schmittjoh/JMSSerializerBundle/blob/master/Resources/config/services.xml,

- :

$serializebuilder = JMS\Serializer\SerializerBuilder::create();
$serializebuilder->setPropertyNamingStrategy(new \JMS\Serializer\Naming\IdenticalPropertyNamingStrategy());
$serializer = $serializebuilder->build();
+13

Source: https://habr.com/ru/post/1675299/


All Articles