Module: EventStoreClient::Serializer::Json

Defined in:
lib/event_store_client/serializer/json.rb

Class Method Summary collapse

Class Method Details

.deserialize(data) ⇒ Hash

Parameters:

  • data (String, Hash)

Returns:

  • (Hash)


8
9
10
11
12
13
14
15
16
17
# File 'lib/event_store_client/serializer/json.rb', line 8

def self.deserialize(data)
  return data if data.is_a?(Hash)

  result = JSON.parse(data)
  return result if result.is_a?(Hash)

  { 'message' => result }
rescue JSON::ParserError
  { 'message' => data }
end

.serialize(data) ⇒ String

Parameters:

  • data (String, Object)

Returns:

  • (String)


21
22
23
24
25
# File 'lib/event_store_client/serializer/json.rb', line 21

def self.serialize(data)
  return data.dup if data.is_a?(String)

  JSON.generate(data)
end