E
E
Evgeny Svirsky2016-01-25 17:49:04
symfony
Evgeny Svirsky, 2016-01-25 17:49:04

How to stop fos_rest from converting camelCase keys to underscore?

There is an object with fields:

firstKey: 'first value' 
secondKey: 'second value' 
thirdKey: 'third value'

If in the controller you give it to Response via Fos Rest JSON, then it will convert it to JSON:
{"first_key": 'first value', 
"second_key": 'second value', 
"third_key": 'third value' }

But it is necessary that the keys are stored in camelCase.
How can I teach him to do this?
I could not find something right away, maybe someone came across.
One of the options is to write your own normilizer, but there may be something simpler that I don't see.
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis, 2016-01-25
@e_svirsky

Well, firstly, this is not a problem of fos_rest, but of a serializer. By default jms is used in fos_rest.
In Google for the request "jms_serializer naming_strategy" you will find this link https://github.com/schmittjoh/JMSSerializerBundle/...
Following which you will find the following piece of config

property_naming:
    id: ~
    strategy: camel_case|identical
    camel_case:
        separator: _
        lower_case: true|false
    enable_annotation: true|false
    enable_cache: true|false

Good luck!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question