class ActiveJob::Serializers::ObjectSerializer

Parent:
Object
Included modules:

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

Public Instance Methods

deserialize(_argument) Show source
# File activejob/lib/active_job/serializers/object_serializer.rb, line 42
def deserialize(_argument)
  raise NotImplementedError
end

Deserializes an argument from a JSON primitive type.

serialize(hash) Show source
# File activejob/lib/active_job/serializers/object_serializer.rb, line 37
def serialize(hash)
  { Arguments::OBJECT_SERIALIZER_KEY => self.class.name }.merge!(hash)
end

Serializes an argument to a JSON primitive type.

serialize?(argument) Show source
# File activejob/lib/active_job/serializers/object_serializer.rb, line 32
def serialize?(argument)
  argument.is_a?(klass)
end

Determines if an argument should be serialized by a serializer.

Private Instance Methods

klass() Show source
# File activejob/lib/active_job/serializers/object_serializer.rb, line 49
def klass # :doc:
  raise NotImplementedError
end

The class of the object that will be serialized.

© 2004–2019 David Heinemeier Hansson
Licensed under the MIT License.