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.25.1 lib/dji_mqtt_connect/railties/message_serializer.rb
dji_mqtt_connect-0.1.25 lib/dji_mqtt_connect/railties/message_serializer.rb
dji_mqtt_connect-0.1.24.1 lib/dji_mqtt_connect/railties/message_serializer.rb
dji_mqtt_connect-0.1.24 lib/dji_mqtt_connect/railties/message_serializer.rb
dji_mqtt_connect-0.1.23.3 lib/dji_mqtt_connect/railties/message_serializer.rb
dji_mqtt_connect-0.1.23.2 lib/dji_mqtt_connect/railties/message_serializer.rb
dji_mqtt_connect-0.1.23.1 lib/dji_mqtt_connect/railties/message_serializer.rb
dji_mqtt_connect-0.1.23 lib/dji_mqtt_connect/railties/message_serializer.rb
dji_mqtt_connect-0.1.22.2 lib/dji_mqtt_connect/railties/message_serializer.rb
dji_mqtt_connect-0.1.22.1 lib/dji_mqtt_connect/railties/message_serializer.rb
dji_mqtt_connect-0.1.22 lib/dji_mqtt_connect/railties/message_serializer.rb
dji_mqtt_connect-0.1.21 lib/dji_mqtt_connect/railties/message_serializer.rb
dji_mqtt_connect-0.1.20.1 lib/dji_mqtt_connect/railties/message_serializer.rb
dji_mqtt_connect-0.1.20 lib/dji_mqtt_connect/railties/message_serializer.rb
dji_mqtt_connect-0.1.19.2 lib/dji_mqtt_connect/railties/message_serializer.rb
dji_mqtt_connect-0.1.19.1 lib/dji_mqtt_connect/railties/message_serializer.rb
dji_mqtt_connect-0.1.19 lib/dji_mqtt_connect/railties/message_serializer.rb
dji_mqtt_connect-0.1.18 lib/dji_mqtt_connect/railties/message_serializer.rb
dji_mqtt_connect-0.1.17.1 lib/dji_mqtt_connect/railties/message_serializer.rb
dji_mqtt_connect-0.1.17 lib/dji_mqtt_connect/railties/message_serializer.rb