diff --git a/lib/active_model/serializer.rb b/lib/active_model/serializer.rb index 79478abb7..80958d067 100644 --- a/lib/active_model/serializer.rb +++ b/lib/active_model/serializer.rb @@ -27,6 +27,11 @@ class Serializer include Links include Meta include Type + class Null < Serializer + def attributes; {}; end + def associations; {}; end + def serializable_hash; {}; end + end # @param resource [ActiveRecord::Base, ActiveModelSerializers::Model] # @return [ActiveModel::Serializer] diff --git a/lib/active_model_serializers/logging.rb b/lib/active_model_serializers/logging.rb index 2a859c413..c18797fbb 100644 --- a/lib/active_model_serializers/logging.rb +++ b/lib/active_model_serializers/logging.rb @@ -81,7 +81,10 @@ def notify_render(*) end def notify_render_payload - { serializer: serializer, adapter: adapter } + { + serializer: serializer || ActiveModel::Serializer::Null, + adapter: adapter || ActiveModelSerializers::Adapter::Null, + } end private