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

Version Path
dji_mqtt_connect-0.1.16.2 lib/dji_mqtt_connect/railties/message_serializer.rb
dji_mqtt_connect-0.1.16.1 lib/dji_mqtt_connect/railties/message_serializer.rb
dji_mqtt_connect-0.1.16 lib/dji_mqtt_connect/railties/message_serializer.rb
dji_mqtt_connect-0.1.15.2 lib/dji_mqtt_connect/railties/message_serializer.rb
dji_mqtt_connect-0.1.15.1 lib/dji_mqtt_connect/railties/message_serializer.rb
dji_mqtt_connect-0.1.15 lib/dji_mqtt_connect/railties/message_serializer.rb
dji_mqtt_connect-0.1.14.1 lib/dji_mqtt_connect/railties/message_serializer.rb
dji_mqtt_connect-0.1.14 lib/dji_mqtt_connect/railties/message_serializer.rb
dji_mqtt_connect-0.1.13.1 lib/dji_mqtt_connect/railties/message_serializer.rb
dji_mqtt_connect-0.1.13 lib/dji_mqtt_connect/railties/message_serializer.rb
dji_mqtt_connect-0.1.12.1 lib/dji_mqtt_connect/railties/message_serializer.rb
dji_mqtt_connect-0.1.12 lib/dji_mqtt_connect/railties/message_serializer.rb
dji_mqtt_connect-0.1.11 lib/dji_mqtt_connect/railties/message_serializer.rb
dji_mqtt_connect-0.1.10 lib/dji_mqtt_connect/railties/message_serializer.rb
dji_mqtt_connect-0.1.9 lib/dji_mqtt_connect/railties/message_serializer.rb
dji_mqtt_connect-0.1.8 lib/dji_mqtt_connect/railties/message_serializer.rb
dji_mqtt_connect-0.1.7 lib/dji_mqtt_connect/railties/message_serializer.rb
dji_mqtt_connect-0.1.6 lib/dji_mqtt_connect/railties/message_serializer.rb
dji_mqtt_connect-0.1.5 lib/dji_mqtt_connect/railties/message_serializer.rb
dji_mqtt_connect-0.1.4.1 lib/dji_mqtt_connect/railties/message_serializer.rb