config/initializers/active_model_serializer.rb
ActiveModel::Serializer.setup do |config|
config.key_format = :lower_camel
end
Currently, only lower_camel
is supported. If we want none just put format_keys :none
class BlogLowerCamelSerializer < ActiveModel::Serializer
format_keys :lower_camel
end
https://github.com/rails-api/active_model_serializers/pull/534
https://github.com/rails-api/active_model_serializers/pull/1029
In the works are multiple types of JSON formats. However, some libraries (like https://github.com/google/google-api-ruby-client) abstract out their interface for hashes. So, to convert to a hash, we can just parse the json.
JSON.parse(MyModelSerializer.new(my_model).to_json)
Or we can add a base class
class BaseSerializer < ActiveModel::Serializer
def hashed
JSON.parse(self.to_json)
end
end
# Then call it like
MyModelSerializer.new(my_model).hashed