jsonapi-rb / jsonapi-deserializable

Conveniently deserialize JSON API payloads into custom hashes.
http://jsonapi-rb.org
MIT License
26 stars 20 forks source link

Deserialize all fields. #7

Closed beauby closed 7 years ago

beauby commented 7 years ago

TL;DR

Deserialization now deserializes the whole payload (no more whitelisting), with the ability to add custom mappings for specific attributes/relationships (and type/id).

Longer explanation

This PR changes the way deserialization works. Current situation is: we loop through the explicitly targeted elements (id/type/attributes/relationships), and for each element, if it is present in the payload, we create the corresponding fields.

With this PR, we do the opposite: we loop through the elements of the payload, and for each of those, if there is a custom block, we use it, otherwise we fall back to a default deserialization scheme (depending on whether it is the type/id, an attribute, a has_one relationship, or a has_many relationship).

This "default deserialization scheme for (type|id|attributes|has_one relationships|has_many relationships)" is overridable by overriding the deserialize_attribute(key, value), deserialize_has_one(key, value, id, type), and deserialize_has_many(key, value, ids, types) methods.

Closes #5 as this removes whitelisting.

codecov-io commented 7 years ago

Current coverage is 100% (diff: 100%)

Merging #7 into master will not change coverage

@@           master    #7   diff @@
===================================
  Files           5     5          
  Lines         146   157    +11   
  Methods         0     0          
  Messages        0     0          
  Branches        0     0          
===================================
+ Hits          146   157    +11   
  Misses          0     0          
  Partials        0     0          

Powered by Codecov. Last update 707a20a...aad510d

beauby commented 7 years ago

Closed by #10.