ruby-grape / grape-active_model_serializers

User active_model_serializers with Grape
MIT License
140 stars 68 forks source link

Convert all AM keys from snake_case to camelCase #68

Closed pke closed 7 years ago

pke commented 7 years ago

When returning JSON it does make no sense to expose the non-JSON ruby like variable naming scheme, imho. Is there a way to configure the serializer to convert the key names to proper json key names?

dblock commented 7 years ago

I don't believe there's an automatic way, but it should be possible with one of Hashie extensions and some wrapper code. Please contribute!

drn commented 7 years ago

@pke - AMS has support for this via the key_transform option

You can specify this options globally:

ActiveModelSerializers.config.key_transform = :camel_lower

Up until this pull request, however, you were not able to specify this for specific render actions because grape-ASM did not pass that option through. If you want it for a specific render action, you can point your Gemfile to:

gem 'grape-active_model_serializers',
  github: 'ruby-grape/grape-active_model_serializers',
  branch: 'pass-ams-options'

and specify the key_transform option explicitly, like:

render user, key_transform: :camel_lower

Let me know if that solves it for you

drn commented 7 years ago

v1.5.1 has been released that includes the fix for passing the key_transform option through to ASM. Closing this out for now. Let me know that doesn't fix it for you