跳至内容 跳至搜索

Base 用于序列化和反序列化自定义对象的类。

示例

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
方法
D
K
S
包含的模块

实例公共方法

反序列化(json)

从 JSON 基本类型中反序列化一个参数。

# File activejob/lib/active_job/serializers/object_serializer.rb, line 44
def deserialize(json)
  raise NotImplementedError
end

序列化(hash)

将一个参数序列化为 JSON 基本类型。

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

是否序列化?(argument)

确定是否应该由序列化器序列化一个参数。

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

实例私有方法

()

将要序列化的对象的类。

# File activejob/lib/active_job/serializers/object_serializer.rb, line 50
def klass # :doc:
  raise NotImplementedError
end