-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fix #425 global root configuration not inherited #427
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
This should be better moved to configs. I think @arthurnn was going to do something like that. |
You mean something like: ActiveModel::Serializer.setup do |config|
config.root = false
config.array_root = false
end Doesn't that mean the array serializer runs into some serious ugliness? # lib/array_serializer.rb
module ActiveModel
class ArraySerializer
include Serializable
def initialize(object, options={})
@object = object
@root = options[:root]
# *Below gets real ugly*
@root = ActiveModel::Serializer::CONFIG.array_root if @root.nil?
@root = options[:resource_name] if @root.nil?
@meta_key = options[:meta_key] || :meta
@meta = options[@meta_key]
@each_serializer = options[:each_serializer]
@options = options.merge(root: nil)
end
end The alternative isn't pretty either, having the following code makes the code base unnecessary complex imho. ActiveModel::Serializer.setup do |config|
config.root = false
end
ActiveModel::ArraySerializer.setup do |config|
config.root = false
end The current I am always available on Skype as |
This commit adds a convert_hash method during the serialization process. It can be overwritten to support converting keys to any format. Two helper methods are included, one for converting the serialized hash keys to camelcase and another to convert them to upcase.
This commit removes the commenter poro and updates the post poro to include snakecase attrs (created_at and updated_at) to test converting keys to various formats such as camelizing.
This commit updates the tests to use the Post poro rather than introducing a new Commenter poro.
This commit updates the test to expect the same key conversion for associations as the parent. This required passing the convert type from the parent to the associations via the serializer method. If it is included in the options, it is set during initialize.
This commit removes the to_sym when converting keys. Tests were updated.
This commit applies the conversion to the root key the same as the model convert type.
Add @options back into serializers for passing custom options
The documentation needs to be updated in the Readme. The intializer method doesn't seem to work at all. Subclassing the serializer works but not as documented. You have to use
instead of
|
Fixed in 700e6b8 |
This fixes that I could not turn off root elements in my json serialization.