Class: Intercom::Lib::TypedJsonDeserializer

Inherits:
Object
  • Object
show all
Defined in:
lib/intercom/lib/typed_json_deserializer.rb

Overview

Responsibility: To decide whether we are deserializing a collection or an entity of a particular type and to dispatch deserialization

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ TypedJsonDeserializer

Returns a new instance of TypedJsonDeserializer.


10
11
12
# File 'lib/intercom/lib/typed_json_deserializer.rb', line 10

def initialize(json)
  @json = json
end

Instance Attribute Details

#jsonObject (readonly)

Returns the value of attribute json


8
9
10
# File 'lib/intercom/lib/typed_json_deserializer.rb', line 8

def json
  @json
end

Instance Method Details

#deserializeObject


14
15
16
17
18
19
20
21
22
# File 'lib/intercom/lib/typed_json_deserializer.rb', line 14

def deserialize
  if blank_object_type?(object_type)
    raise DeserializationError, "No type field was found to facilitate deserialization"
  elsif list_object_type?(object_type)
    deserialize_collection(json[object_entity_key])
  else # singular object type
    deserialize_object(json)
  end
end