mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 15:23:06 +00:00
Create DefaultSerializer so that as_json uses same interface.
This is to ensure that PORO's as_json is called if no serializer is specified. Original behaviour was that serializable_hash was being called, overriding the as_json method.
This commit is contained in:
@@ -1,6 +1,15 @@
|
||||
require "active_support/core_ext/class/attribute"
|
||||
|
||||
module ActiveModel
|
||||
class DefaultSerializer
|
||||
attr_reader :object
|
||||
def initialize(object)
|
||||
@object = object
|
||||
end
|
||||
def serializable_hash
|
||||
@object.as_json
|
||||
end
|
||||
end
|
||||
# Active Model Array Serializer
|
||||
#
|
||||
# It serializes an Array, checking if each element that implements
|
||||
@@ -30,7 +39,7 @@ module ActiveModel
|
||||
if serializer
|
||||
serializer.new(item, @options)
|
||||
else
|
||||
item
|
||||
DefaultSerializer.new(item)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user