-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle special-case of Array serializer with unserializable elements
- Loading branch information
Showing
3 changed files
with
8 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,10 +42,9 @@ def use_adapter? | |
@_serializer_opts[:scope] ||= serialization_scope | ||
@_serializer_opts[:scope_name] = _serialization_scope | ||
|
||
object = serializer.new(resource, @_serializer_opts) | ||
|
||
if serializer == ActiveModel::Serializer.config.array_serializer | ||
resource = ActiveModel::Serializer::Adapter.create(object, @_adapter_opts) unless object.objects.all? {|i| i.nil?} | ||
begin | ||
object = serializer.new(resource, @_serializer_opts) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
bf4
Author
Member
|
||
rescue ActiveModel::Serializer::ArraySerializer::Error | ||
else | ||
resource = ActiveModel::Serializer::Adapter.create(object, @_adapter_opts) | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
module ActiveModel | ||
class Serializer | ||
class ArraySerializer | ||
Error = Class.new(StandardError) | ||
include Enumerable | ||
delegate :each, to: :@objects | ||
|
||
|
@@ -14,7 +15,9 @@ def initialize(objects, options = {}) | |
ActiveModel::Serializer.serializer_for(object) | ||
) | ||
|
||
unless serializer_class.nil? | ||
if serializer_class.nil? | ||
fail Error, "No serializer found for object: #{object.inspect}" | ||
This comment has been minimized.
Sorry, something went wrong.
bf4
Author
Member
|
||
else | ||
serializer_class.new(object, options.except(:serializer)) | ||
end | ||
end | ||
|
what do you think about renaming
object
toserializer_instance
?