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
def klass
Money
end
end
Class Method Summary
- .new ⇒ ObjectSerializer constructor
Instance Attribute Summary
-
#deserialize(hash)
readonly
Deserializes an argument from a JSON primitive type.
-
#serialize?(argument) ⇒ Boolean
readonly
Determines if an argument should be serialized by a serializer.
::Singleton
- Included
#duplicable? |
|
Instance Method Summary
-
#klass
The class of the object that will be serialized.
-
#serialize(hash)
readonly
Serializes an argument to a JSON primitive type.
Constructor Details
.new ⇒ ObjectSerializer
# File 'activejob/lib/active_job/serializers/object_serializer.rb', line 31
def initialize super @template = { Arguments::OBJECT_SERIALIZER_KEY => self.class.name }.freeze end
Instance Attribute Details
#deserialize(hash) (readonly)
Deserializes an argument from a JSON primitive type.
# File 'activejob/lib/active_job/serializers/object_serializer.rb', line 47
delegate :serialize?, :serialize, :deserialize, to: :instance
#serialize?(argument) ⇒ Boolean
(readonly)
Determines if an argument should be serialized by a serializer.
# File 'activejob/lib/active_job/serializers/object_serializer.rb', line 37
delegate :serialize?, :serialize, :deserialize, to: :instance
Instance Method Details
#klass
The class of the object that will be serialized.
# File 'activejob/lib/active_job/serializers/object_serializer.rb', line 52
def klass raise NotImplementedError, "#{self.class.name} should implement a public #klass method" end
#serialize(hash) (readonly)
Serializes an argument to a JSON primitive type.
# File 'activejob/lib/active_job/serializers/object_serializer.rb', line 42
delegate :serialize?, :serialize, :deserialize, to: :instance