-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Optional camelization of roots and attributes #388
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
Conversation
There is one issue remaining as I discovered today. Associations won't get their keys camel cased. Any ideas where I could hook into that to make sure camelization happens? |
Fix camelization doc
Can you try to implement something like this against new master and open a new pr?. If you can't no worries it is in the roadmap :). I'm closing this issue for now but in case you want to implement it ... We would like a generic |
Ok let me try this against master then |
WOW incredible improvements in master since last I checked, nice refactorings and good work everyone involved in that 👍 |
@mhenrixon thanks |
I am almost done with a new version that works with master and in my opinion the result is a whole lot cleaner but I had a couple of questions.
|
About 2. I'd add a new file named something like |
That is actually a great suggestion but don't that mean I would have to duplicate this effort for all my 20 serializers? I could of course create a base serializer that the others inherit from but it still feels wrong. |
FYI the global settings are broken in master. ActiveSupport.on_load(:active_model_serializers) do
# Disable for all serializers (except ArraySerializer)
ActiveModel::Serializer.root = false
# Disable for ArraySerializer
ActiveModel::ArraySerializer.root = false
end Neither of those work for me using the master branch locally. It still adds the root elements to be serialized. |
@mhenrixon there's no run_load_hooks inside AMS because there's no lazy load. So the code you pasted doesn't work. All you have to do is put # Disable for all serializers (except ArraySerializer)
ActiveModel::Serializer.root = false
# Disable for ArraySerializer
ActiveModel::ArraySerializer.root = false Inside an |
I'd love some quick feedback on this since I really need this functionality in a current project. I do not want to have to set the key for every attribute in every serializer in the project I am working on :)
I will later add possibility of overriding the
render json: @someobject, camelize: true
but that got a little more complicated than I have time for right now. I still need that functionality just not critical right now.