Module: Jinx::JSON::Deserializer
- Defined in:
- lib/jinx/json/deserializer.rb
Overview
JSON => Resource deserializer.
This Deserializer reconstitutes a jinxed object from a JSON string built by a Serializable.
Instance Method Summary collapse
-
#json_create(json) ⇒ Jinx::Resource
The deserialized object.
Instance Method Details
#json_create(json) ⇒ Jinx::Resource
Returns the deserialized object.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/jinx/json/deserializer.rb', line 25 def json_create(json) # the thread-local oid => object hash visited = Thread.current[:jinx_json_deserialized] # the payload vh = json['data'] # the oid oid = vh.delete('object_id') # If the object has already been built, then return that object. ref = visited[oid] if ref then # Fill in a place-holder with content. ref.merge_attributes(vh) unless vh.empty? return ref end # Make the new object from the attribute => value hash. visited[oid] = new(vh) end |