From 71478a9adf174db500c9ec038a47d048500dd951 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ku=CC=88bler?= Date: Mon, 13 Jan 2020 13:55:00 +0100 Subject: [PATCH 1/2] =?UTF-8?q?Don=E2=80=99t=20build=20empty=20objects=20o?= =?UTF-8?q?n=20missing=20linked=20resources.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit According to the Spec (https://jsonapi.org/format/#document-resource-object-linkage), empty relationships are null by default. Object.new is roughly equal to an empty JSON ({}) in context of this deserializer. It is hard for us to recognize missing or non-present relationships if we have an object with no attributes. To avoid this, instead of a PORO, just nil is returned as reference to a non-present relationships. --- lib/json-api-vanilla/parser.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/json-api-vanilla/parser.rb b/lib/json-api-vanilla/parser.rb index 3bb8a50..9f41111 100644 --- a/lib/json-api-vanilla/parser.rb +++ b/lib/json-api-vanilla/parser.rb @@ -72,6 +72,9 @@ def self.build(hash) obj = objects[[o_hash['type'], o_hash['id']]] if o_hash['relationships'] o_hash['relationships'].each do |key, value| + # Instantiate ref initially + ref = nil + if value['data'] data = value['data'] if data.is_a?(Array) @@ -96,7 +99,6 @@ def self.build(hash) end end - ref = ref || Object.new set_key(obj, key, ref, original_keys) rel_links[ref] = value['links'] From 61641b627aecd92ac444ba94d2f104a914fa9ac8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ku=CC=88bler?= Date: Thu, 6 Feb 2020 09:56:09 +0100 Subject: [PATCH 2/2] Bump version to 1.0.3. --- lib/json-api-vanilla/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/json-api-vanilla/version.rb b/lib/json-api-vanilla/version.rb index 6cf3754..e8228e3 100644 --- a/lib/json-api-vanilla/version.rb +++ b/lib/json-api-vanilla/version.rb @@ -2,7 +2,7 @@ module JSON module Api module Vanilla - VERSION = '1.0.2' + VERSION = '1.0.3' end end end