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

DeSerialize data: null is replaced with [] for hasOne relationships #37

Closed
rgant opened this issue Jan 26, 2017 · 5 comments
Closed

DeSerialize data: null is replaced with [] for hasOne relationships #37

rgant opened this issue Jan 26, 2017 · 5 comments

Comments

@rgant
Copy link
Contributor

rgant commented Jan 26, 2017

The DeSerialize function replaces null data with an empty array. This results in an error when loading empty relationships:

Error: DSJsonApiAdapter, Load Relations expected non array
    at js-data-jsonapi.js:1249
    at processQueue (angular-1.5.8.js:16383)
    at angular-1.5.8.js:16399
    at Scope.$eval (angular-1.5.8.js:17682)
    at Scope.$digest (angular-1.5.8.js:17495)
    at Scope.$apply (angular-1.5.8.js:17790)
    at done (angular-1.5.8.js:11831)
    at completeRequest (angular-1.5.8.js:12033)
    at XMLHttpRequest.requestLoaded (angular-1.5.8.js:11966)
This was referenced Jan 26, 2017
@rgant
Copy link
Contributor Author

rgant commented Jan 26, 2017

I think this was just a typo, instead of short circuiting to new DeSerializeResult(null, null); the first parameter was accidentally made an empty array [].

@rgant
Copy link
Contributor Author

rgant commented Jan 26, 2017

Ok, so I was overly optimistic. It seems that js-data and js-data-http both care strongly about the falsinisity of the response from the server. Good old JS treats [] as truthy so it was legitimately being DeSerialized. However this still leaves onInjectJsonApiData with an error when DeSeralize returns an empty array for a hasOne relationship.

@rgant
Copy link
Contributor Author

rgant commented Jan 30, 2017

Asked js-data people about this on their slack and they asked me to ask on stackoverflow:
http://stackoverflow.com/questions/41938330/how-to-deserialize-null-response-in-js-data

@BlairAllegroTech
Copy link
Owner

Can we close this now after merging your changes or is there still an issue?

@rgant
Copy link
Contributor Author

rgant commented Feb 14, 2017

Yes, this ticket can be closed. I never got any response from js-data to my
question. I think they have moved on to v3 and so everything is different.
We might have to adapt soon as well. In my experience libraries like this
don't maintain old versions long.

@rgant rgant closed this as completed Feb 14, 2017
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

2 participants