-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Description
def fetch_serializer(resource, env)
endpoint = env['api.endpoint']
options = build_options_from_endpoint(endpoint)
serializer = options.fetch(:serializer, ActiveModel::Serializer.serializer_for(resource))
return nil unless serializer
options[:scope] = endpoint unless options.key?(:scope)
# ensure we have an root to fallback on
options[:resource_name] = default_root(endpoint) if resource.respond_to?(:to_ary)
serializer.new(resource, options.merge(other_options(env)))
endwhich uses serializer = ActiveModel::Serializer.serializer_for(resource)).new(resource, options) which is (somewhat intentionally) not supported in 0.10.
I'd be in favor of adding a grape serializer something or other (grape users can help here).
In the meantime, this may work
Grape::Formatter::ActiveModelSerializers.module_eval do # might be instance_eval
class << self
def fetch_serializer(resource, env)
endpoint = env['api.endpoint']
options = build_options_from_endpoint(endpoint)
serializer = options.fetch(:serializer, ActiveModel::Serializer.serializer_for(resource))
- return nil unless serializer
options[:scope] = endpoint unless options.key?(:scope)
# ensure we have an root to fallback on
options[:resource_name] = default_root(endpoint) if resource.respond_to?(:to_ary)
+ serialization_options = options.merge(adapter: :json, serializer: merge!(other_options(env))).serializer)
+ ActiveModel::SerializableResource.new(resource, serialization_options) # assuming you want json, I don't know which adapter to use
- serializer.new(resource, options.merge(other_options(env)))
end
end
endRelated issues