Skip to content

Handling of null data #14

Open
Open
@TeamNautilus

Description

@TeamNautilus

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions