-
Notifications
You must be signed in to change notification settings - Fork 196
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
Cannot read attributes of null
#203
Comments
I don't believe https://jsonapi.org/format/#document-top-level
So it should be either single resource
or array (empty or with resources)
|
Having the same issue. @aalimovs is it possible you missed the "or null"? Or are you interpreting it differently?
It feels like every time I read the spec I find another way I've misunderstood it 😛 |
@davidgovea good catch 😅 I missed that. We do actually have Can you share a code example when you get that error? |
Here's an example: https://codesandbox.io/s/jsonapi-deserializer-error-oie91 It's not ideal, but sometimes we have a need for data-less |
Here is my diff --git a/node_modules/jsonapi-serializer/lib/deserializer.js b/node_modules/jsonapi-serializer/lib/deserializer.js
index 1cb7c1a..d8fc6e4 100644
--- a/node_modules/jsonapi-serializer/lib/deserializer.js
+++ b/node_modules/jsonapi-serializer/lib/deserializer.js
@@ -31,8 +31,9 @@ module.exports = function (opts) {
return result
});
}
-
- if (Array.isArray(jsonapi.data)) {
+ if (!jsonapi.data) {
+ return jsonapi.data
+ } else if (Array.isArray(jsonapi.data)) {
return collection();
} else {
return resource(); |
When I run deserialize on
{ data: null }
i get the following error:cannot read attributes of null
but it is an valid json-api response. Is this expected behavior?The text was updated successfully, but these errors were encountered: