Class: Moleculer::Serializers::Json

Inherits:
Object
  • Object
show all
Defined in:
lib/moleculer/serializers/json.rb

Overview

Serializes data packets to and from JSON

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Json

Returns a new instance of Json.



8
9
10
11
# File 'lib/moleculer/serializers/json.rb', line 8

def initialize(config)
  @logger = config.logger.get_child("[SERIALIZER]")
  @config = config
end

Instance Method Details

#deserialize(message) ⇒ Object



17
18
19
20
21
# File 'lib/moleculer/serializers/json.rb', line 17

def deserialize(message)
  JSON.parse(message)
rescue StandardError => e
  @config.handle_error(e)
end

#serialize(message) ⇒ Object



13
14
15
# File 'lib/moleculer/serializers/json.rb', line 13

def serialize(message)
  message.to_h.to_json
end