123456789_123456789_123456789_123456789_123456789_

Class: ActiveJob::Serializers::ObjectSerializer

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
self, ::Singleton
Inherits: Object
Defined in: activejob/lib/active_job/serializers/object_serializer.rb

Overview

::ActiveJob::Base class for serializing and deserializing custom objects.

Example:

class MoneySerializer < ActiveJob::Serializers::ObjectSerializer
  def serialize(money)
    super("amount" => money.amount, "currency" => money.currency)
  end

  def deserialize(hash)
    Money.new(hash["amount"], hash["currency"])
  end

  private

    def klass
      Money
    end
end

Instance Attribute Summary

::Singleton - Included

#duplicable?

::Singleton instances are not duplicable:

Instance Method Summary

  • #serialize(hash) readonly

    Serializes an argument to a JSON primitive type.

  • #klass private

    The class of the object that will be serialized.

Instance Attribute Details

#deserialize(json) (readonly)

Deserializes an argument from a JSON primitive type.

Raises:

  • (NotImplementedError)
[ GitHub ]

  
# File 'activejob/lib/active_job/serializers/object_serializer.rb', line 44

delegate :serialize?, :serialize, :deserialize, to: :instance

#serialize?(argument) ⇒ Boolean (readonly)

Determines if an argument should be serialized by a serializer.

[ GitHub ]

  
# File 'activejob/lib/active_job/serializers/object_serializer.rb', line 34

delegate :serialize?, :serialize, :deserialize, to: :instance

Instance Method Details

#klass (private)

The class of the object that will be serialized.

Raises:

  • (NotImplementedError)
[ GitHub ]

  
# File 'activejob/lib/active_job/serializers/object_serializer.rb', line 50

def klass # :doc:
  raise NotImplementedError
end

#serialize(hash) (readonly)

Serializes an argument to a JSON primitive type.

[ GitHub ]

  
# File 'activejob/lib/active_job/serializers/object_serializer.rb', line 39

delegate :serialize?, :serialize, :deserialize, to: :instance