Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to change default naming strategy #128

Closed
MVSAdmin opened this issue Jul 26, 2013 · 6 comments
Closed

Switch to change default naming strategy #128

MVSAdmin opened this issue Jul 26, 2013 · 6 comments

Comments

@MVSAdmin
Copy link

Hi there!

I can't find a possibility to switch the naming strategy so it's not converting from camelCase to underscored. I really don't understand why this is the default behaviour and setting a SerializedName annotation for all properties in all entities is really nothing we'd like to do.

So, am I missing some switch somewhere?
If not, would it be possible to add that?

Cheers, Anton

@AntonStoeckl
Copy link

I see there is a IdenticalPropertyNamingStrategy, but how to plug it in, so it's used?

Cheers, Anton

@slavafomin
Copy link

Hey @schmittjoh!

Could you elaborate on this issue please?

I have the same requirement. It would be great if I would be able to change naming strategy in one place instead of specifying "SerializedName" annotation on every property.

Thank you!

@slavafomin
Copy link

I found solution in this thread:
schmittjoh/JMSSerializerBundle#270

For now, I'm using this configuration override:

parameters:
    jms_serializer.serialized_name_annotation_strategy.class: JMS\Serializer\Naming\IdenticalPropertyNamingStrategy

But it's not respecting the @SerializedName annotation overloads.

I would love to see this configuration moved to bundle config though )

Also, it would be great to have an annotation, say @NamingStrategy on a class level, that will allow us to change naming strategy for a specific class only.

@johnpancoast
Copy link

johnpancoast commented Jan 24, 2017

@schmittjoh or anyone, Is there any update on this? This seems a bit redundant to have to do and could be the default IMO. I can help if I know it's something you want to change in the lib. :)

/**
 * @JMS\SerializedName("fooBar")
 */
protected $fooBar;

@goetas
Copy link
Collaborator

goetas commented Apr 24, 2017

Can be solved with a custom naming strategy

@goetas goetas closed this as completed Apr 24, 2017
@ianef
Copy link

ianef commented Mar 13, 2019

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.yml
services:
    ....
    jms_serializer.serialized_name_annotation_strategy:
        class: JMS\Serializer\Naming\SerializedNameAnnotationStrategy
        arguments:
            - '@jms_serializer.identical_property_naming_strategy'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants