Skip to content

Commit 170db3b

Browse files
Trek Glowackibf4
authored andcommitted
Allow users to globally opt out of automatic lookup
1 parent 8aaaa44 commit 170db3b

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

docs/general/configuration_options.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ The following configuration options can be set on `ActiveModel::Serializer.confi
55
## General
66

77
- `adapter`: The [adapter](adapters.md) to use. Possible values: `:attributes, :json, :json_api`. Default: `:attributes`.
8+
- `automatic_lookup`: Whether serializer should be automatically looked up or manually provided. Default: `true`
89

910
## JSON API
1011

lib/action_controller/serialization.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ def serialization_scope
2121
end
2222

2323
def get_serializer(resource, options = {})
24+
unless options[:serializer] || options[:each_serializer] || ActiveModel::Serializer.config.automatic_lookup
25+
return resource
26+
end
27+
2428
if !use_adapter?
2529
warn 'ActionController::Serialization#use_adapter? has been removed. '\
2630
"Please pass 'adapter: false' or see ActiveSupport::SerializableResource.new"

lib/active_model/serializer/configuration.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def config.array_serializer
2020

2121
config.adapter = :attributes
2222
config.jsonapi_resource_type = :plural
23+
config.automatic_lookup = true
2324
end
2425
end
2526
end

0 commit comments

Comments
 (0)