1

Im having a problem when sending a Cloud Code Request with parameters as a HashMap. The Funny thing is that if I send a request with empty parameters, it works perfectly fine. Here is my code for the request (Updated with ishmaelMakitla's answer) :

Map<String, Object> par = new HashMap<String, Object>();
par.put("ingredients", new String[]{"hey"});
ParseCloud.callFunctionInBackground("", par, new FunctionCallback() {
  @Override
  public void done(Object o, Throwable throwable) {
    Log.v("28", "" + o);
    Log.v("27", "" + throwable.getMessage());
    for (Object obj : (ArrayList)o) {
      Log.v("29",""+((ParseObject) obj).get("title"));
    }
  }

  @Override
  public void done(Object object, ParseException e) {
    Log.v("26", "" + object);
    if (e != null) {
      Log.v("27", "" + e);
    }
    for (Object obj : (ArrayList)object) {
      Log.v("25",""+((ParseObject) obj).get("title"));
    }
  }
});

And my Cloud Code Method:

Parse.Cloud.define ('getFoo', function (req, res) {
    var arrayIngredients = [];
    arrayIngredients = req.params.ingredients;
    var recepyQuery = new Parse.Query("Foos");
    recepyQuery.find( {
    success: function(result) {
        res.success(result);    
    },
    error: function() {
        res.error("Nothing here");    
    }    
    });
});

This code works perfectly, but if i uncomment the par.put(...) part, it gives this error:

    com.parse.ParseException: java.lang.IllegalArgumentException: invalid type for ParseObject: class [Ljava.lang.String;

This is my error stack:

05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err: com.parse.ParseException: java.lang.IllegalArgumentException: invalid type for ParseObject: class [Ljava.lang.String;
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err:     at com.parse.ParseTaskUtils$2$1.run(ParseTaskUtils.java:114)
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err:     at android.os.Handler.handleCallback(Handler.java:733)
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:95)
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err:     at android.os.Looper.loop(Looper.java:146)
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5653)
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err:     at java.lang.reflect.Method.invokeNative(Native Method)
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err:     at java.lang.reflect.Method.invoke(Method.java:515)
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err:     at dalvik.system.NativeStart.main(Native Method)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: Caused by: java.lang.IllegalArgumentException: invalid type for ParseObject: class [Ljava.lang.String;
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err:     at com.parse.ParseEncoder.encode(ParseEncoder.java:136)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err:     at com.parse.ParseEncoder.encode(ParseEncoder.java:97)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err:     at com.parse.ParseRESTCommand.<init>(ParseRESTCommand.java:138)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err:     at com.parse.ParseRESTCloudCommand.<init>(ParseRESTCloudCommand.java:22)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err:     at com.parse.ParseRESTCloudCommand.callFunctionCommand(ParseRESTCloudCommand.java:28)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err:     at com.parse.ParseCloudCodeController.callFunctionInBackground(ParseCloudCodeController.java:28)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err:     at com.parse.ParseCloud$1.then(ParseCloud.java:64)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err:     at com.parse.ParseCloud$1.then(ParseCloud.java:60)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err:     at bolts.Task$15.run(Task.java:917)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err:     at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:105)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err:     at bolts.Task.completeAfterTask(Task.java:908)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err:     at bolts.Task.continueWithTask(Task.java:715)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err:     at bolts.Task.continueWithTask(Task.java:726)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err:     at bolts.Task$13.then(Task.java:818)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err:     at bolts.Task$13.then(Task.java:806)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err:     at bolts.Task$15.run(Task.java:917)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err:     at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:105)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err:     at bolts.Task.completeAfterTask(Task.java:908)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err:     at bolts.Task.continueWithTask(Task.java:715)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err:     at bolts.Task.continueWithTask(Task.java:690)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err:     at bolts.Task.onSuccessTask(Task.java:806)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err:     at bolts.Task.onSuccessTask(Task.java:796)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err:     at bolts.Task.onSuccessTask(Task.java:830)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err:     at com.parse.ParseCloud.callFunctionInBackground(ParseCloud.java:60)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err:     at com.parse.ParseCloud.callFunctionInBackground(ParseCloud.java:99)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err:     at com.parse.starter.MainActivity.onCreate(MainActivity.java:62)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err:     at android.app.Activity.performCreate(Activity.java:5541)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2368)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2464)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err:     at android.app.ActivityThread.access$900(ActivityThread.java:172)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err:  ... 7 more

Is this a mistake I made or there is an issue with Parse? Im using Parse Server and Parse's Android SDK 1.13.0

9
  • 1
    Try changing your callFunctionInBackground to not use Generic type (Object) and instead using ParseCloud.callFunctionInBackground("getFoo", par, new FunctionCallback(){...} - give it a try and let me know if this helps. Commented May 30, 2016 at 10:09
  • I just tried it, and the error is the same... thanks anyway! I jus updated the question with your sugestion Commented May 30, 2016 at 10:26
  • Must you have two done methods? Maybe update your code with the latest code you've got. Also what happens if your HashMap explicitly uses string array for value type (instead of Object)? Commented May 30, 2016 at 10:35
  • Yes is mandatory to include the two methods if I use your method. I just tried it with the String[] type as the value type of the Hashmap and the result is the same. (I also tried it with the my main option only, and the result is the same) Commented May 30, 2016 at 10:40
  • What do you send back as result? Could you print the log of your result just before res.success(result); - I am wondering if the error has to be with the parameters you send or the response. Commented May 30, 2016 at 10:49

1 Answer 1

2

Instead of passing the String[] in the value, simply pass a String, for this you should change your requesting code as follows -

Map<String, Object> par = new HashMap<String, Object>();
par.put("ingredients", "someIngredientValue"});
ParseCloud.callFunctionInBackground("getFoo", par, new FunctionCallback() {
  @Override
  public void done(Object o, Throwable throwable) {
    Log.v("28", "" + o);
    Log.v("27", "" + throwable.getMessage());
    for (Object obj : (ArrayList)o) {
      Log.v("29",""+((ParseObject) obj).get("title"));
    }
  } 
//the rest of your code ...

On the receiving end, you then say request.params.ingredients - this should give you 'someIngredientValue'. I hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.