Class: ActiveJob::Serializers::ObjectSerializer
- Inherits:
-
Object
- Object
- ActiveJob::Serializers::ObjectSerializer
- Includes:
- Singleton
- Defined in:
- lib/rails_6_polyfills/activejob/serializers.rb
Overview
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
Direct Known Subclasses
Instance Method Summary collapse
-
#deserialize(_argument) ⇒ Object
Deserializes an argument from a JSON primitive type.
-
#serialize(hash) ⇒ Object
Serializes an argument to a JSON primitive type.
-
#serialize?(argument) ⇒ Boolean
Determines if an argument should be serialized by a serializer.
Instance Method Details
#deserialize(_argument) ⇒ Object
Deserializes an argument from a JSON primitive type.
98 99 100 |
# File 'lib/rails_6_polyfills/activejob/serializers.rb', line 98 def deserialize(_argument) raise NotImplementedError end |
#serialize(hash) ⇒ Object
Serializes an argument to a JSON primitive type.
93 94 95 |
# File 'lib/rails_6_polyfills/activejob/serializers.rb', line 93 def serialize(hash) {Arguments::OBJECT_SERIALIZER_KEY => self.class.name}.merge!(hash) end |
#serialize?(argument) ⇒ Boolean
Determines if an argument should be serialized by a serializer.
88 89 90 |
# File 'lib/rails_6_polyfills/activejob/serializers.rb', line 88 def serialize?(argument) argument.is_a?(klass) end |