Sha256: 38ce9da96b1adff7531131cae4d89b49e7d0338b0a1677e8f13f93501dc87925
Contents?: true
Size: 769 Bytes
Versions: 49
Compression:
Stored size: 769 Bytes
Contents
# frozen_string_literal: true module DjiMqttConnect module Railties class MessageSerializer < ActiveJob::Serializers::ObjectSerializer def serialize(message) stringified_hash = message.to_h.deep_stringify_keys # Strip the extra data element stringified_hash.delete("_data") super( "type" => message.class.name, "payload" => stringified_hash ) end def deserialize(hash) # Rebuild the message, re-insert the data hash message_class = hash["type"].constantize message_payload = hash["payload"].merge("_data" => {}) message_class.new(message_payload) end private def klass DjiMqttConnect::Message end end end end
Version data entries
49 entries across 49 versions & 1 rubygems