-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
There is an issue when root element is configured this way :
ActiveSupport.on_load(:active_model_serializers) do
# Disable for all serializers (except ArraySerializer)
ActiveModel::Serializer.root = false
# Disable for ArraySerializer
ActiveModel::ArraySerializer.root = false
endActually the gem is doing that :
def self.version(version, superclass = ActiveModel::Serializer, &block)
base_class = self
vklass = Class.new(superclass) do
self.root(base_class._root)
alias_method base_class._name.to_sym, :object
singleton_class.class_eval do
define_method(:to_s) do
"(#{base_class.name} VERSION: #{version})"
end
alias inspect to_s
endIt sets root (or not) directly based on parameters passed to the serializer :
[1] poc_api_app(#<Class>) » superclass
=> ActiveModel::Serializer < Object
[2] poc_api_app(#<Class>) » superclass._root?
=> false
[3] poc_api_app(#<Class>) » base_class
=> UserSerializer < ActiveModel::VersionSerializer
[4] poc_api_app(#<Class>) » base_class._root?
=> true
You can notice that it doesn't use my configuration and still includes the root element because it doesn't check if superclass._root? is false.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels