Skip to content

Issue with Cloud function which returns list of custom object #63

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

Closed
ghost opened this issue Jan 30, 2019 · 8 comments
Closed

Issue with Cloud function which returns list of custom object #63

ghost opened this issue Jan 30, 2019 · 8 comments

Comments

@ghost
Copy link

ghost commented Jan 30, 2019

Hi, I have a problem with Cloud Function.

When for exemple, I made this sample from the example in the lib :

void getAllItems() async {
    var apiResponse = await TestObject().getAll();

    if (apiResponse.success && apiResponse.result != null) {
      for (var test in apiResponse.result) {
        print(ApplicationConstants.keyAppName + ": " + (test as TestObject).title);
      }
    } else {
      print(ApplicationConstants.keyAppName + ": " + apiResponse.error.message);
    }
  }

I have this payload (with debug print, and it prints correctly the title of my test object in DB)

Payload: [{"className":"TestObject","objectId":"A","createdAt":"B","updatedAt":"C","title":"Hello"}]

But when I tried to retrieve it with Cloud Function, like this :

getObjects() async {
    var function = ParseCloudFunction('getObjects');
    ParseResponse response = await function.execute();
    return response;
  }

The payload is different from the first payload

Payload: [{title: Hello, createdAt: B, updatedAt: C, objectId: A, __type: Object, className: TestObject}]

And when I try to print the title of my test object like before (before, it works well), it doesn't work and I have this error :

Dart Error: Unhandled exception:
E/flutter (23910): type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'TestObject' in type cast
@pcg92
Copy link
Contributor

pcg92 commented Jan 30, 2019

Can you try it?
response.result["title"];

@ghost
Copy link
Author

ghost commented Jan 30, 2019

Yes :

response.result["title"]: null

@pcg92
Copy link
Contributor

pcg92 commented Jan 30, 2019

Umm, and response["title"]? I think the problem is how to get the value from the _InternalLinkedHashMap.
print(response) = Payload: [{title: Hello, createdAt: B, updatedAt: C, objectId: A, __type: Object, className: TestObject}]?

@ghost
Copy link
Author

ghost commented Jan 30, 2019

I can't do response["title"] because response is a ParseResponse object

@pcg92
Copy link
Contributor

pcg92 commented Jan 30, 2019

Im doing this and its working for me, hope it can help.

js cloud code:
return Promise.resolve({"token":token});
and dart:

var response = await function.execute(parameters: params);
    if(response.success){
      var token = response.result["result"]["token"];
}

@ghost
Copy link
Author

ghost commented Jan 31, 2019

Mmm, I think there is no problem when you return a simple object like String, but when you try to return complex custom object, it fails.

Try to return a custom object instead string and tell me what happens please.

@ghost ghost changed the title Issue with Cloud function return Issue with Cloud function which returns list of custom object Feb 5, 2019
@ghost
Copy link
Author

ghost commented Feb 5, 2019

I confirm what I said before @pcegarra

@phillwiggins
Copy link
Member

This wouldn't be the work of the library. A cloud function can return any type of data, not just ParseObjects. To do this a custom JSON parser would need to be created to handle the data manually.

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