class ActiveJob::Serializers::ObjectSerializer
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
def klass
Money
end
end
Inherits From
-
module
Singleton
Public instance methods
Deserializes an argument from a JSON primitive type.
Source code GitHub
# File activejob/lib/active_job/serializers/object_serializer.rb, line 43
def deserialize(hash)
raise NotImplementedError, "#{self.class.name} should implement a public #deserialize(hash) method"
end
The class of the object that will be serialized.
Source code GitHub
# File activejob/lib/active_job/serializers/object_serializer.rb, line 48
def klass
raise NotImplementedError, "#{self.class.name} should implement a public #klass method"
end
Serializes an argument to a JSON primitive type.
Source code GitHub
# File activejob/lib/active_job/serializers/object_serializer.rb, line 37
def serialize(hash)
hash[Arguments::OBJECT_SERIALIZER_KEY] = self.class.name
hash
end
Determines if an argument should be serialized by a serializer.
Source code GitHub
# File activejob/lib/active_job/serializers/object_serializer.rb, line 32
def serialize?(argument)
argument.is_a?(klass)
end