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

Failure on null has-one payloads #3451

Closed
sirvine opened this issue Jun 26, 2015 · 1 comment
Closed

Failure on null has-one payloads #3451

sirvine opened this issue Jun 26, 2015 · 1 comment

Comments

@sirvine
Copy link

sirvine commented Jun 26, 2015

My API generates a payload for a collection, where a single record looks like this:

    {
      "id": "16",
      "type": "contracts",
      "links": {
        "self": "/api/v1/contracts/16"
      },
      "attributes": {
        "title": "Example Title",
        "current-cycle-id": 40,
        "created-at": "2015-05-22T09:38:26.418-04:00",
        "updated-at": "2015-05-22T09:38:26.418-04:00"
      },
      "relationships": {
        "cycles": {
          "links": {
            "self": "/api/v1/contracts/16/relationships/cycles",
            "related": "/api/v1/contracts/16/cycles"
          }
        },
        "supplier": {
          "links": {
            "self": "/api/v1/contracts/16/relationships/supplier",
            "related": "/api/v1/contracts/16/supplier"
          },
          "data": null
        },
        "tower": {
          "links": {
            "self": "/api/v1/contracts/16/relationships/tower",
            "related": "/api/v1/contracts/16/tower"
          },
          "data": {
            "type": "towers",
            "id": "1"
          }
        },
        "client": {
          "links": {
            "self": "/api/v1/contracts/16/relationships/client",
            "related": "/api/v1/contracts/16/client"
          },
          "data": {
            "type": "clients",
            "id": "1"
          }
        }
      }
    }

Note that two of the has-one relationships (tower and client) include a value under the data key, but the supplier relationship is null.

The JSONAPIAdapter is chasing down all of the relationship links correctly. In the case of supplier, the resulting payload looks like:

  {
    "data": null
  }

When the JSONAPISerializer attempts to normalize this payload, it applies map to null, which causes a failure.

@sirvine
Copy link
Author

sirvine commented Jun 27, 2015

That did the trick. Thanks!

@sirvine sirvine closed this as completed Jun 27, 2015
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