Skip to content

Cannot represent resource links #22

@rogerrohrbach

Description

@rogerrohrbach
  • JSON API doc version: 0.15.0
  • Python version: n/a
  • Operating System: n/a

Summary

It is not possible to serialize or deserialize resource links, i.e., a links member within a JSON API resource object.

Description

A JSON API resource object MAY contain a links member. This is a valid JSON API resource object:

{
  "type": "articles",
  "id": "1",
  "attributes": {
    "title": "Rails is Omakase"
  },
  "links": {
    "self": "http://example.com/articles/1"
  }
}

json-api-doc will not properly deserialize a document having this object as its primary data:

import json_api_doc

doc = {
  "data": {
    "type": "articles",
    "id": "1",
    "attributes": {
      "title": "Rails is Omakase"
    },
    "links": {
      "self": "http://example.com/articles/1"
    }
  }
}

obj = json_api_doc.deserialize(doc)

print(obj)  # {'type': 'articles', 'id': '1', 'title': 'Rails is Omakase'}

Moreover, it is not possible to generate this document by serializing a Python object. If links is passed in data, it becomes an attribute; using the links keyword argument is inappropriate, as it creates a top-level member, outside of the primary data.

Links within a relationships member are similarly mishandled.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions