tjhillard/json-api-deserialize

Doesn't work if record has multiple relationships.

geoidesic opened this issue · 0 comments

The json string below will only end up with the first record deserialised.
It works correctly if I remove the entity_type relationship.
Having done some inspecting with break-points, it looks like it is running into exceptions within normalizer which then stops the iteration from continuing.

message: "Property description must be an object: undefined"
stack: "TypeError: Property description must be an object: undefined↵    at Function.defineProperty (<anonymous>)↵    at normalizeGivenObject (webpack-internal:///./node_modules/json-api-deserialize/dist/packages/normalizer/normalizer.func.js:79:24)↵    at normalizeGivenObject (webpack-internal:///./node_modules/json-api-deserialize/dist/packages/normalizer/normalizer.func.js:58:21)↵    at normalizeGivenObject (webpack-internal:///./node_modules/json-api-deserialize/dist/packages/normalizer/normalizer.func.js:75:17)↵    at normalizeGivenObject (webpack-internal:///./node_modules/json-api-deserialize/dist/packages/normalizer/normalizer.func.js:70:17)↵    at normalizeGivenObject (webpack-internal:///./node_modules/json-api-deserialize/dist/packages/normalizer/normalizer.func.js:31:25)↵    at Object.exports.normalize (webpack-internal:///./node_modules/json-api-deserialize/dist/packages/normalizer/normalizer.func.js:87:5)↵    at Deserializer.getReturnObject (webpack-internal:///./node_modules/json-api-deserialize/dist/packages/deserializer/deserializer.class.js:146:44)↵    at Deserializer.getDeserialized (webpack-internal:///./node_modules/json-api-deserialize/dist/packages/deserializer/deserializer.class.js:65:25)↵    at exports.deserialize (webpack-internal:///./node_modules/json-api-deserialize/dist/packages/deserializer/deserializer.func.js:5:44)"
__proto__: Error

Here's the JSONAPI raw data that causes this:

{
  "data": [
        {
            "type": "users",
            "id": "1",
            "attributes": {
                "active": true,
                "name": "Sherlock",
                "surname": "Holmes",
                "created": "2019-10-31T18:45:52+00:00",
                "modified": "2019-10-31T18:45:52+00:00"
            },
            "relationships": {
                "role": {
                    "links": {
                        "self": "/api/roles/2"
                    },
                    "data": {
                        "type": "roles",
                        "id": "2"
                    }
                },
                "entity-type": {
                    "links": {
                        "self": "/api/entity_types/1"
                    },
                    "data": {
                        "type": "entity-types",
                        "id": "1"
                    }
                }
            },
            "links": {
                "self": "/api/users/1"
            }
        },
        {
            "type": "users",
            "id": "3",
            "attributes": {
                "active": true,
                "name": "John",
                "surname": "Watson",
                "created": "2019-10-31T18:45:52+00:00",
                "modified": "2019-10-31T18:45:52+00:00"
            },
            "relationships": {
                "role": {
                    "links": {
                        "self": "/api/roles/3"
                    },
                    "data": {
                        "type": "roles",
                        "id": "3"
                    }
                },
                "entity-type": {
                    "links": {
                        "self": "/api/entity_types/1"
                    },
                    "data": {
                        "type": "entity-types",
                        "id": "1"
                    }
                }
            },
            "links": {
                "self": "/api/users/3"
            }
        }
    ],
    "included": [
        {
            "type": "roles",
            "id": "2",
            "attributes": {
                "name": "sidekick",
                "description": null,
                "created": "2019-10-31T18:45:52+00:00",
                "modified": "2019-10-31T18:45:52+00:00"
            },
            "links": {
                "self": "/api/roles/2"
            }
        },
        {
            "type": "entity-types",
            "id": "1",
            "attributes": {
                "name": "individual",
                "created": "2019-10-31T18:45:52+00:00",
                "modified": "2019-10-31T18:45:52+00:00"
            },
            "links": {
                "self": "/api/entity_types/1"
            }
        },
        {
            "type": "roles",
            "id": "3",
            "attributes": {
                "name": "hero",
                "description": null,
                "created": "2019-10-31T18:45:52+00:00",
                "modified": "2019-10-31T18:45:52+00:00"
            },
            "links": {
                "self": "/api/roles/3"
            }
        }
    ]
}