BlairAllegroTech / js-data-jsonapi

JsonApi Adapter for js-data

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

rgant opened this issue · comments

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)

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 [].

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.

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

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

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.