Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling of null data #14

Open
TeamNautilus opened this issue Jun 30, 2020 · 0 comments
Open

Handling of null data #14

TeamNautilus opened this issue Jun 30, 2020 · 0 comments

Comments

@TeamNautilus
Copy link
Contributor

As stated in the JSON API specs a resource linkage object may have these values:

Resource linkage MUST be represented as one of the following:

    null for empty to-one relationships.
    an empty array ([]) for empty to-many relationships.
    a single resource identifier object for non-empty to-one relationships.
    an array of resource identifier objects for non-empty to-many relationships.

https://jsonapi.org/format/#document-resource-object-linkage

After the json-api-vanilla parsing is return an Object instead.

To reproduce:

  • Change the example.json:84 from
    "data": { "type": "people", "id": "9" }
    to
    "data": null

  • Add the following test:

it "should handle null data" do
   expect(doc.data.first.comments.last.author).to be_nil
end

Result:

     expected: nil
     got: #<Object:0x0000557bbcd4bd08>

We have noticed the fallback creation of an object here:

ref = ref || Object.new

Removing that line make all specs green but maybe it will results in other "untested" issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant