-
Notifications
You must be signed in to change notification settings - Fork 27.4k
$resource.query turn strings into objects in response array #6314
Comments
+1 |
1 similar comment
+1 |
A fix for this would be trivial, I'll submit a patch |
If you guys find bugs that you really want fixed, just ping me, I'm bored and I like fixing stuff :c |
…hen isArray is true Previously non-object literals would be thrown out of Resource responses with isArray===true, or otherwise converted into Objects (in the case of string literals). The reason for this is because shallowClearAndCopy iterates over keys, and copies keys into the destination. Iterating over String keys results in integer keys, with a single-character value. Not converting non-objects to Resources means that you lose the ability to perform Resource operations on them. However, they become usable as strings, numbers, or booleans, which is important. In the future, it would be useful to make these useful as Resources while still retaining their primitive value usefulness. Closes angular#6314
Why would your REST server return an array in that form? |
@rodyhaddad there's no real use case, but it's besides the point, we shouldn't be trying to convert strings/numbers/booleans into objects --- or rather, we shouldn't be trying to copy properties of those primitives into a Resource object. Because, we lose the number/booleans, and we convert strings into garbage. This is wrong. |
@caitp okay, just wanted to make sure before commenting on your PR :-) |
@caitp @rodyhaddad It's real use case if you have crazy data model. On server side json serializer replaces duplicates by UIDs and sometimes objects in main array already are in fields of first object. That’s why i have object and string in one array. Of course i used hypothetical example. I tried fix it but I could not find one who breaks my response. |
So this should be a pretty high-impact bug then, because thats basically the definition of most web services |
Simpler use case is requesting: and i should be getting an array like this: but instead i get garbage... |
@deanshub what he's saying is that it's a weird use for ngResource, because resource is expected to be talking to someones definition of a RESTful web service, which will structure data according to someones definition of "appropriately". The assumption is that the returned array is an array of individual resources (with their own unique identifiers, and their own content), so the contents of the array should always be objects. Otherwise, $http would work just as well for resources like this, without this issue. So, whether it's a case of abuse of ngResource, or bad assumptions on our part, it doesn't really matter. But if you are running into this, you might consider just using $http instead, and then converting actual resources into Resource objects if you need to, while keeping the primitive/literals as they are. That is basically the work around until it lands, or in case it doesn't. |
Got it, hope you pull request will be accepted |
…hen isArray is true Previously non-object literals would be thrown out of Resource responses with isArray===true, or otherwise converted into Objects (in the case of string literals). The reason for this is because shallowClearAndCopy iterates over keys, and copies keys into the destination. Iterating over String keys results in integer keys, with a single-character value. Not converting non-objects to Resources means that you lose the ability to perform Resource operations on them. However, they become usable as strings, numbers, or booleans, which is important. In the future, it would be useful to make these useful as Resources while still retaining their primitive value usefulness. Closes angular#6314 Closes angular#7741
…hen isArray is true Previously non-object literals would be thrown out of Resource responses with isArray===true, or otherwise converted into Objects (in the case of string literals). The reason for this is because shallowClearAndCopy iterates over keys, and copies keys into the destination. Iterating over String keys results in integer keys, with a single-character value. Not converting non-objects to Resources means that you lose the ability to perform Resource operations on them. However, they become usable as strings, numbers, or booleans, which is important. In the future, it would be useful to make these useful as Resources while still retaining their primitive value usefulness. Closes angular#6314 Closes angular#7741
…hen isArray is true Previously non-object literals would be thrown out of Resource responses with isArray===true, or otherwise converted into Objects (in the case of string literals). The reason for this is because shallowClearAndCopy iterates over keys, and copies keys into the destination. Iterating over String keys results in integer keys, with a single-character value. Not converting non-objects to Resources means that you lose the ability to perform Resource operations on them. However, they become usable as strings, numbers, or booleans, which is important. In the future, it would be useful to make these useful as Resources while still retaining their primitive value usefulness. Closes angular#6314 Closes angular#7741
In our case, we just wanted to return a simple string, but with the existing implementation it was not possible. We had to first assign that string to the value of an object's key, and only then it would work. Otherwise something like "hello"would be transformed into Thanks @caitp for fixing this :) |
@pensierinmusica, I believe this fix handles Literals inside a JSON. It does not work if the output string in a pure Literal (i.e. not wrapped in an array or an object). |
@pensierinmusica. I am having the exact issue you mentioned right now. I am doing a get with parameters and just need a single string but its transforming like yours. Was this issue not fixed? Edit: Nevermind, it was my bad. I was returning a string which is incorrect for this architecture. I should have returned an object. |
Yup, still happens. |
Version 1.5.1 and I still get happening. |
This issue is closed and the original problem is supposed to have been fixed. |
Still there. Don't know what else to add to the issue. |
http://plnkr.co/edit/6Up7bFGica8qOYTs3Gwk?p=preview
bug.html
array.json
result
The text was updated successfully, but these errors were encountered: