Sam
Sam

Reputation: 1828

JMS Serializer: overriding default naming strategy in symfony 4 has no effect

I found this thread proposing a neat way of overriding globally the default naming strategy in config.yml

but this is for symfony 3 and I am on symfony 4 so I added the line to my config > packages > jms_serializer.yaml but this has no effect at all.

jms_serializer:
  visitors:
    xml_serialization:
        format_output: '%kernel.debug%'
  property_naming:
    id: 'jms_serializer.identical_property_naming_strategy'

Does anyone understand why ?

I do dependency injection of SerializerInterface $serializer to use the serializer as it is not possible to call the service from AbstractController in SF4. Controller is deprecated in SF4.

Upvotes: 3

Views: 2425

Answers (2)

Bart McLeod
Bart McLeod

Reputation: 161

Add jms_serializer.camel_case_naming_strategy.class: JMS\Serializer\Naming\IdenticalPropertyNamingStrategy to your parameters configuration.

Upvotes: -1

Dawid Góra
Dawid Góra

Reputation: 165

Try removing var/cache manually. When I cleared cache with cache:clear command it didn't work, but after I cleaned it manually it did!

I hope this solution will help you too.

Upvotes: 6

Related Questions